Diff for /loncom/interface/londocs.pm between versions 1.321 and 1.326

version 1.321, 2008/12/15 03:02:19 version 1.326, 2009/01/28 11:51:22
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Documents  # Documents
 #  #
 # $Id$  # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #  #
 # LON-CAPA is free software; you can redistribute it and/or modify  # LON-CAPA is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by  # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or  # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  # (at your option) any later version.
 #  #
 # LON-CAPA is distributed in the hope that it will be useful,  # LON-CAPA is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.  # GNU General Public License for more details.
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #  #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   
   
 package Apache::londocs;  package Apache::londocs;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::imsexport;  use Apache::imsexport;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
 use LONCAPA::map();  use LONCAPA::map();
 use Apache::lonratedt();  use Apache::lonratedt();
 use Apache::lonxml;  use Apache::lonxml;
 use Apache::lonclonecourse;  use Apache::lonclonecourse;
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
 use HTML::Entities;  use HTML::Entities;
 use GDBM_File;  use GDBM_File;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Cwd;  use Cwd;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 my $iconpath;  my $iconpath;
   
 my %hash;  my %hash;
   
 my $hashtied;  my $hashtied;
 my %alreadyseen=();  my %alreadyseen=();
   
 my $hadchanges;  my $hadchanges;
   
   
 my %help=();  my %help=();
   
   
   sub mapread {
 sub mapread {      my ($coursenum,$coursedom,$map)=@_;
     my ($coursenum,$coursedom,$map)=@_;      return
     return        &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.       $map);
      $map);  }
 }  
   sub storemap {
 sub storemap {      my ($coursenum,$coursedom,$map)=@_;
     my ($coursenum,$coursedom,$map)=@_;      my ($outtext,$errtext)=
     my ($outtext,$errtext)=        &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.        $map,1);
       $map,1);      if ($errtext) { return ($errtext,2); }
     if ($errtext) { return ($errtext,2); }     
           $hadchanges=1;
     $hadchanges=1;      return ($errtext,0);
     return ($errtext,0);  }
 }  
   
   
   sub authorhosts {
 sub authorhosts {      my %outhash=();
     my %outhash=();      my $home=0;
     my $home=0;      my $other=0;
     my $other=0;      foreach my $key (keys(%env)) {
     foreach my $key (keys(%env)) {   if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
  if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {      my $role=$1;
     my $role=$1;      my $realm=$2;
     my $realm=$2;      my ($start,$end)=split(/\./,$env{$key});
     my ($start,$end)=split(/\./,$env{$key});      if (($start) && ($start>time)) { next; }
     if (($start) && ($start>time)) { next; }      if (($end) && (time>$end)) { next; }
     if (($end) && (time>$end)) { next; }      my ($ca,$cd);
     my ($ca,$cd);      if ($1 eq 'au') {
     if ($1 eq 'au') {   $ca=$env{'user.name'};
  $ca=$env{'user.name'};   $cd=$env{'user.domain'};
  $cd=$env{'user.domain'};      } else {
     } else {   ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
  ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);      }
     }      my $allowed=0;
     my $allowed=0;      my $myhome=&Apache::lonnet::homeserver($ca,$cd);
     my $myhome=&Apache::lonnet::homeserver($ca,$cd);      my @ids=&Apache::lonnet::current_machine_ids();
     my @ids=&Apache::lonnet::current_machine_ids();      foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
     foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }      if ($allowed) {
     if ($allowed) {   $home++;
  $home++;   $outhash{'home_'.$ca.'@'.$cd}=1;
  $outhash{'home_'.$ca.'@'.$cd}=1;      } else {
     } else {   $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
  $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;   $other++;
  $other++;      }
     }   }
  }      }
     }      return ($home,$other,%outhash);
     return ($home,$other,%outhash);  }
 }  
   
   sub dumpbutton {
 sub dumpbutton {      my ($home,$other,%outhash)=&authorhosts();
     my ($home,$other,%outhash)=&authorhosts();      my $type = &Apache::loncommon::course_type();
     my $type = &Apache::loncommon::course_type();      if ($home+$other==0) { return ''; }
     if ($home+$other==0) { return ''; }      if ($home) {
     if ($home) {   return '<div>'.
  return '<div>'.      '<input type="submit" name="dumpcourse" value="'.
     '<input type="submit" name="dumpcourse" value="'.      &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
     &mt('Dump '.$type.' DOCS to Construction Space').'" />'.      &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').
     &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').      '</div>';
     '</div>';      } else {
     } else {   return '<div>'.
  return '<div>'.       &mt('Dump '.$type.
      &mt('Dump '.$type.   ' DOCS to Construction Space: available on other servers').
  ' DOCS to Construction Space: available on other servers').   '</div>';
  '</div>';      }
     }  }
 }  
   sub clean {
 sub clean {      my ($title)=@_;
     my ($title)=@_;      $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;      return $title;
     return $title;  }
 }  
   
   
   sub dumpcourse {
 sub dumpcourse {      my ($r) = @_;
     my ($r) = @_;      my $type = &Apache::loncommon::course_type();
     my $type = &Apache::loncommon::course_type();      $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
     $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').        '<form name="dumpdoc" method="post">');
       '<form name="dumpdoc" method="post">');      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));      my ($home,$other,%outhash)=&authorhosts();
     my ($home,$other,%outhash)=&authorhosts();      unless ($home) { return ''; }
     unless ($home) { return ''; }      my $origcrsid=$env{'request.course.id'};
     my $origcrsid=$env{'request.course.id'};      my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);      if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {  # Do the dumping
 # Do the dumping   unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
  unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }   my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
  my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});   $r->print('<h3>'.&mt('Copying Files').'</h3>');
  $r->print('<h3>'.&mt('Copying Files').'</h3>');   my $title=$env{'form.authorfolder'};
  my $title=$env{'form.authorfolder'};   $title=&clean($title);
  $title=&clean($title);   my %replacehash=();
  my %replacehash=();   foreach my $key (keys(%env)) {
  foreach my $key (keys(%env)) {      if ($key=~/^form\.namefor\_(.+)/) {
     if ($key=~/^form\.namefor\_(.+)/) {   $replacehash{$1}=$env{$key};
  $replacehash{$1}=$env{$key};      }
     }   }
  }   my $crs='/uploaded/'.$env{'request.course.id'}.'/';
  my $crs='/uploaded/'.$env{'request.course.id'}.'/';   $crs=~s/\_/\//g;
  $crs=~s/\_/\//g;   foreach my $item (keys(%replacehash)) {
  foreach my $item (keys(%replacehash)) {      my $newfilename=$title.'/'.$replacehash{$item};
     my $newfilename=$title.'/'.$replacehash{$item};      $newfilename=~s/\.(\w+)$//;
     $newfilename=~s/\.(\w+)$//;      my $ext=$1;
     my $ext=$1;      $newfilename=&clean($newfilename);
     $newfilename=&clean($newfilename);      $newfilename.='.'.$ext;
     $newfilename.='.'.$ext;      my @dirs=split(/\//,$newfilename);
     my @dirs=split(/\//,$newfilename);      my $path='/home/'.$ca.'/public_html';
     my $path='/home/'.$ca.'/public_html';      my $makepath=$path;
     my $makepath=$path;      my $fail=0;
     my $fail=0;      for (my $i=0;$i<$#dirs;$i++) {
     for (my $i=0;$i<$#dirs;$i++) {   $makepath.='/'.$dirs[$i];
  $makepath.='/'.$dirs[$i];   unless (-e $makepath) {
  unless (-e $makepath) {       unless(mkdir($makepath,0777)) { $fail=1; }
     unless(mkdir($makepath,0777)) { $fail=1; }    }
  }      }
     }      $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
     $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');      if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {   if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
  if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {      print $fh &Apache::lonclonecourse::rewritefile(
     print $fh &Apache::lonclonecourse::rewritefile(           &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),       (%replacehash,$crs => '')
      (%replacehash,$crs => '')      );
     );   } else {
  } else {      print $fh
     print $fh           &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);         }
        }   $fh->close();
  $fh->close();      } else {
     } else {   $fail=1;
  $fail=1;      }
     }      if ($fail) {
     if ($fail) {   $r->print('<span class="LC_error">'.&mt('fail').'</span>');
  $r->print('<span class="LC_error">'.&mt('fail').'</span>');      } else {
     } else {   $r->print('<span class="LC_success">'.&mt('ok').'</span>');
  $r->print('<span class="LC_success">'.&mt('ok').'</span>');      }
     }   }
  }      } else {
     } else {  # Input form
 # Input form   unless ($home==1) {
  unless ($home==1) {      $r->print(
     $r->print(        '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
       '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');   }
  }   foreach my $key (sort(keys(%outhash))) {
  foreach my $key (sort(keys(%outhash))) {      if ($key=~/^home_(.+)$/) {
     if ($key=~/^home_(.+)$/) {   if ($home==1) {
  if ($home==1) {      $r->print(
     $r->print(    '<input type="hidden" name="authorspace" value="'.$1.'" />');
   '<input type="hidden" name="authorspace" value="'.$1.'" />');   } else {
  } else {      $r->print('<option value="'.$1.'">'.$1.' - '.
     $r->print('<option value="'.$1.'">'.$1.' - '.        &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
       &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');   }
  }      }
     }   }
  }   unless ($home==1) {
  unless ($home==1) {      $r->print('</select>');
     $r->print('</select>');   }
  }   my $title=$origcrsdata{'description'};
  my $title=$origcrsdata{'description'};   $title=~s/[\/\s]+/\_/gs;
  $title=~s/[\/\s]+/\_/gs;   $title=&clean($title);
  $title=&clean($title);   $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
  $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'                   .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
                  .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');   &tiehash();
  &tiehash();   $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
  $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'                   .&Apache::loncommon::start_data_table()
                  .&Apache::loncommon::start_data_table()                   .&Apache::loncommon::start_data_table_header_row()
                  .&Apache::loncommon::start_data_table_header_row()                   .'<th>'.&mt('Internal Filename').'</th>'
                  .'<th>'.&mt('Internal Filename').'</th>'                   .'<th>'.&mt('Title').'</th>'
                  .'<th>'.&mt('Title').'</th>'                   .'<th>'.&mt('Save as ...').'</th>'
                  .'<th>'.&mt('Save as ...').'</th>'                   .&Apache::loncommon::end_data_table_header_row());
                  .&Apache::loncommon::end_data_table_header_row());   foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
  foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {      $r->print(&Apache::loncommon::start_data_table_row()
     $r->print(&Apache::loncommon::start_data_table_row()                       .'<td>'.$file.'</td>');
                      .'<td>'.$file.'</td>');      my ($ext)=($file=~/\.(\w+)$/);
     my ($ext)=($file=~/\.(\w+)$/);      my $title=$hash{'title_'.$hash{
     my $title=$hash{'title_'.$hash{   'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
  'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};      $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
     $r->print('<td>'.($title?$title:'&nbsp;').'</td>');      if (!$title) {
     if (!$title) {   $title=$file;
  $title=$file;      } else {
     } else {   $title=~s|/|_|g;
  $title=~s|/|_|g;      }
     }      $title=~s/\.(\w+)$//;
     $title=~s/\.(\w+)$//;      $title=&clean($title);
     $title=&clean($title);      $title.='.'.$ext;
     $title.='.'.$ext;      $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
     $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"                       .&Apache::loncommon::end_data_table_row());
                      .&Apache::loncommon::end_data_table_row());   }
  }   $r->print(&Apache::loncommon::end_data_table());
  $r->print(&Apache::loncommon::end_data_table());   &untiehash();
  &untiehash();   $r->print(
  $r->print(    '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $type DOCS").'" /></p></form>');
   '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $type DOCS").'" /></p></form>');      }
     }  }
 }  
   
   
   sub exportbutton {
 sub exportbutton {      my $type = &Apache::loncommon::course_type();
     my $type = &Apache::loncommon::course_type();      return '<div>'.
     return '<div>'.              '<input type="submit" name="exportcourse" value="'.
             '<input type="submit" name="exportcourse" value="'.              &mt('Export '.$type.' to IMS').'" />'.
             &mt('Export '.$type.' to IMS').'" />'.      &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'</div>';
     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'</div>';  }
 }  
   
   
   sub exportcourse {
 sub exportcourse {      my $r=shift;
     my $r=shift;      my $type = &Apache::loncommon::course_type();
     my $type = &Apache::loncommon::course_type();      my %discussiontime = &Apache::lonnet::dump('discussiontimes',
     my %discussiontime = &Apache::lonnet::dump('discussiontimes',                                                 $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});      my $numdisc = keys(%discussiontime);
     my $numdisc = keys(%discussiontime);      my $navmap = Apache::lonnavmaps::navmap->new();
     my $navmap = Apache::lonnavmaps::navmap->new();      if (!defined($navmap)) {
     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);          $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package').
     my $curRes;                    '<h2>IMS Export Failed</h2>'.
     my $outcome;                    '<div class="LC_error">'.
                     &mt('Unable to retrieve information about course contents').
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},                    '</div><a href="/adm/coursedocs">'.&mt('Return to Course Editor').'</a>');
                                             ['finishexport']);          &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
     if ($env{'form.finishexport'}) {          return;
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      }
                                             ['archive','discussion']);      my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
       my $curRes;
         my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');      my $outcome;
         my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');  
         if (@exportitems == 0 && @discussions == 0) {      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
             $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created.  Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';                                              ['finishexport']);
         } else {      if ($env{'form.finishexport'}) {
             my $now = time;          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
             my %symbs;                                              ['archive','discussion']);
             my $manifestok = 0;  
             my $imsresources;          my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
             my $tempexport;          my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
             my $copyresult;          if (@exportitems == 0 && @discussions == 0) {
             my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);              $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created.  Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
             if ($manifestok) {          } else {
                 &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);              my $now = time;
                 close($ims_manifest);              my %symbs;
               my $manifestok = 0;
 #Create zip file in prtspool              my $imsresources;
                 my $imszipfile = '/prtspool/'.              my $tempexport;
                 $env{'user.name'}.'_'.$env{'user.domain'}.'_'.              my $copyresult;
                    time.'_'.rand(1000000000).'.zip';              my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
                 my $cwd = &Cwd::getcwd();              if ($manifestok) {
                 my $imszip = '/home/httpd/'.$imszipfile;                  &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
                 chdir $tempexport;                  close($ims_manifest);
                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");  
                 close(OUTPUT);  #Create zip file in prtspool
                 chdir $cwd;                  my $imszipfile = '/prtspool/'.
                 $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);                  $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
                 if ($copyresult) {                     time.'_'.rand(1000000000).'.zip';
                     $outcome .= &mt('The following errors occurred during export - [_1]',$copyresult);                  my $cwd = &Cwd::getcwd();
                 }                  my $imszip = '/home/httpd/'.$imszipfile;
             } else {                  chdir $tempexport;
                 $outcome = '<br />'.&mt('Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.').'<br />';                  open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
             }                  close(OUTPUT);
         }                  chdir $cwd;
         $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));                  $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);
  $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));                  if ($copyresult) {
         $r->print($outcome);                      $outcome .= &mt('The following errors occurred during export - [_1]',$copyresult);
         $r->print(&Apache::loncommon::end_page());                  }
     } else {              } else {
         my $display;                  $outcome = '<br />'.&mt('Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.').'<br />';
         $display = '<form name="exportdoc" method="post">'."\n";              }
         $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');          }
         $display .= '<table border="0" cellspacing="0" cellpadding="3">'.          $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
                     '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.   $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
                     '<input type="button" value="check all" '.          $r->print($outcome);
                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.          $r->print(&Apache::loncommon::end_page());
                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.      } else {
                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.          my $display;
                     '<td>&nbsp;</td><td>&nbsp;</td>'.          $display = '<form name="exportdoc" method="post">'."\n";
                     '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.          $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');
                     '</b></legend><input type="button" value="check all"'.          $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
                     ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.                      '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.
                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.                      '<input type="button" value="check all" '.
                     ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.                      'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
                     '</tr></table>';                      '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
         my $curRes;                      ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
         my $depth = 0;                      '<td>&nbsp;</td><td>&nbsp;</td>'.
         my $count = 0;                      '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.
         my $boards = 0;                      '</b></legend><input type="button" value="check all"'.
         my $startcount = 5;                      ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
         my %parent = ();                      '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
         my %children = ();                      ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
         my $lastcontainer = $startcount;                      '</tr></table>';
         my @bgcolors = ('#F6F6F6','#FFFFFF');          my $curRes;
         $display .= '<table cellspacing="0"><tr>'.          my $depth = 0;
             '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";          my $count = 0;
         if ($numdisc > 0) {          my $boards = 0;
             $display.='<b>Export&nbsp;discussion posts?</b>'."\n";          my $startcount = 5;
         }          my %parent = ();
         $display.='&nbsp;</td></tr>';          my %children = ();
         while ($curRes = $it->next()) {          my $lastcontainer = $startcount;
             if (ref($curRes)) {          my @bgcolors = ('#F6F6F6','#FFFFFF');
                 $count ++;          $display .= '<table cellspacing="0"><tr>'.
             }              '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";
             if ($curRes == $it->BEGIN_MAP()) {          if ($numdisc > 0) {
                 $depth++;              $display.='<b>Export&nbsp;discussion posts?</b>'."\n";
                 $parent{$depth} = $lastcontainer;          }
             }          $display.='&nbsp;</td></tr>';
             if ($curRes == $it->END_MAP()) {          while ($curRes = $it->next()) {
                 $depth--;              if (ref($curRes)) {
                 $lastcontainer = $parent{$depth};                  $count ++;
             }              }
             if (ref($curRes)) {              if ($curRes == $it->BEGIN_MAP()) {
                 my $symb = $curRes->symb();                  $depth++;
                 my $ressymb = $symb;                  $parent{$depth} = $lastcontainer;
                 if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {              }
                     unless ($ressymb =~ m|adm/wrapper/adm|) {              if ($curRes == $it->END_MAP()) {
                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';                  $depth--;
                     }                  $lastcontainer = $parent{$depth};
                 }              }
                 my $color = $count%2;              if (ref($curRes)) {
                 $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".                  my $symb = $curRes->symb();
                     '<input type="checkbox" name="archive" value="'.$count.'" ';                  my $ressymb = $symb;
                 if (($curRes->is_sequence()) || ($curRes->is_page())) {                  if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
                     my $checkitem = $count + $boards + $startcount;                      unless ($ressymb =~ m|adm/wrapper/adm|) {
                     $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';                          $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                 }                      }
                 $display .= ' />'."\n";                  }
                 for (my $i=0; $i<$depth; $i++) {                  my $color = $count%2;
                     $display .= '<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" /><img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" />'."\n";                  $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
                 }                      '<input type="checkbox" name="archive" value="'.$count.'" ';
                 if ($curRes->is_sequence()) {                  if (($curRes->is_sequence()) || ($curRes->is_page())) {
                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";                      my $checkitem = $count + $boards + $startcount;
                     $lastcontainer = $count + $startcount + $boards;                      $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
                 } elsif ($curRes->is_page()) {                  }
                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";                  $display .= ' />'."\n";
                     $lastcontainer = $count + $startcount + $boards;                  for (my $i=0; $i<$depth; $i++) {
                 }                      $display .= '<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" /><img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" />'."\n";
                 my $currelem = $count+$boards+$startcount;                  }
                 $children{$parent{$depth}} .= $currelem.':';                  if ($curRes->is_sequence()) {
                 $display .= '&nbsp;'.$curRes->title().'</td>';                      $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";
                 if ($discussiontime{$ressymb} > 0) {                      $lastcontainer = $count + $startcount + $boards;
                     $boards ++;                  } elsif ($curRes->is_page()) {
                     $currelem = $count+$boards+$startcount;                      $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";
                     $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";                      $lastcontainer = $count + $startcount + $boards;
                 } else {                  }
                     $display .= '<td colspan="2">&nbsp;</td>'."\n";                  my $currelem = $count+$boards+$startcount;
                 }                  $children{$parent{$depth}} .= $currelem.':';
             }                  $display .= '&nbsp;'.$curRes->title().'</td>';
         }                  if ($discussiontime{$ressymb} > 0) {
         my $scripttag = qq|                      $boards ++;
 <script>                      $currelem = $count+$boards+$startcount;
                       $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";
 function checkAll(field) {                  } else {
     if (field.length > 0) {                      $display .= '<td colspan="2">&nbsp;</td>'."\n";
         for (i = 0; i < field.length; i++) {                  }
             field[i].checked = true ;              }
         }          }
     } else {          my $scripttag = qq|
         field.checked = true  <script>
     }  
 }  function checkAll(field) {
                                                                                       if (field.length > 0) {
 function uncheckAll(field) {          for (i = 0; i < field.length; i++) {
     if (field.length > 0) {              field[i].checked = true ;
         for (i = 0; i < field.length; i++) {          }
             field[i].checked = false ;      } else {
         }          field.checked = true
     } else {      }
         field.checked = false ;  }
     }                                                                                 
 }  function uncheckAll(field) {
       if (field.length > 0) {
 function propagateCheck(item) {          for (i = 0; i < field.length; i++) {
     if (document.exportdoc.elements[item].checked == true) {              field[i].checked = false ;
         containerCheck(item)          }
     }      } else {
 }           field.checked = false ;
       }
 function containerCheck(item) {  }
     document.exportdoc.elements[item].checked = true  
     var numitems = $count + $boards + $startcount  function propagateCheck(item) {
     var parents = new Array(numitems)      if (document.exportdoc.elements[item].checked == true) {
     for (var i=$startcount; i<numitems; i++) {          containerCheck(item)
         parents[i] = new Array      }
     }  }
         |;  
   function containerCheck(item) {
         foreach my $container (sort { $a <=> $b } (keys(%children))) {      document.exportdoc.elements[item].checked = true
             my @contents = split(/:/,$children{$container});      var numitems = $count + $boards + $startcount
             for (my $i=0; $i<@contents; $i ++) {      var parents = new Array(numitems)
                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";      for (var i=$startcount; i<numitems; i++) {
             }          parents[i] = new Array
         }      }
           |;
         $scripttag .= qq|  
     if (parents[item].length > 0) {          foreach my $container (sort { $a <=> $b } (keys(%children))) {
         for (var j=0; j<parents[item].length; j++) {              my @contents = split(/:/,$children{$container});
             containerCheck(parents[item][j])              for (my $i=0; $i<@contents; $i ++) {
         }                  $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
      }                 }
 }          }
   
 </script>          $scripttag .= qq|
         |;      if (parents[item].length > 0) {
  $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',          for (var j=0; j<parents[item].length; j++) {
  $scripttag));              containerCheck(parents[item][j])
  $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));          }
  $r->print($display.'</table>'.       }  
                   '<p><input type="hidden" name="finishexport" value="1">'.  }
                   '<input type="submit" name="exportcourse" value="'.  
                   &mt('Export '.$type.' DOCS').'" /></p></form>'.  </script>
   &Apache::loncommon::end_page());          |;
     }   $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',
 }   $scripttag));
    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
 sub create_ims_store {   $r->print($display.'</table>'.
     my ($now,$manifestok,$outcome,$tempexport) = @_;                    '<p><input type="hidden" name="finishexport" value="1">'.
     $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';                    '<input type="submit" name="exportcourse" value="'.
     my $ims_manifest;                    &mt('Export '.$type.' DOCS').'" /></p></form>');
     if (!-e $$tempexport) {      }
         mkdir($$tempexport,0700);  }
     }  
     $$tempexport .= '/'.$now;  sub create_ims_store {
     if (!-e $$tempexport) {      my ($now,$manifestok,$outcome,$tempexport) = @_;
         mkdir($$tempexport,0700);      $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
     }      my $ims_manifest;
     $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};      if (!-e $$tempexport) {
     if (!-e $$tempexport) {          mkdir($$tempexport,0700);
         mkdir($$tempexport,0700);      }
     }      $$tempexport .= '/'.$now;
     if (!-e "$$tempexport/resources") {      if (!-e $$tempexport) {
         mkdir("$$tempexport/resources",0700);          mkdir($$tempexport,0700);
     }      }
 # open manifest file      $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
     my $manifest = '/imsmanifest.xml';      if (!-e $$tempexport) {
     my $manifestfilename = $$tempexport.$manifest;          mkdir($$tempexport,0700);
     if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {      }
         $$manifestok=1;      if (!-e "$$tempexport/resources") {
         print $ims_manifest          mkdir("$$tempexport/resources",0700);
 '<?xml version="1.0" encoding="UTF-8"?>'."\n".      }
 '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.  # open manifest file
 ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.      my $manifest = '/imsmanifest.xml';
 ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.      my $manifestfilename = $$tempexport.$manifest;
 ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.      if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
 '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.          $$manifestok=1;
 '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".          print $ims_manifest
 '  <metadata>  '<?xml version="1.0" encoding="UTF-8"?>'."\n".
     <schema></schema>  '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
     <imsmd:lom>  ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
       <imsmd:general>  ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
         <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>  ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
         <imsmd:title>  '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
           <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>  '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
         </imsmd:title>  '  <metadata>
       </imsmd:general>      <schema></schema>
     </imsmd:lom>      <imsmd:lom>
   </metadata>'."\n".        <imsmd:general>
 '  <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".          <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
 '    <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.          <imsmd:title>
 ' structure="hierarchical">'."\n".            <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
 '      <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'          </imsmd:title>
     } else {        </imsmd:general>
         $$outcome .= 'An error occurred opening the IMS manifest file.<br />'      </imsmd:lom>
 ;    </metadata>'."\n".
     }  '  <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
     return $ims_manifest;  '    <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
 }  ' structure="hierarchical">'."\n".
   '      <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
 sub build_package {      } else {
     my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;          $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
 # first iterator to look for dependencies  ;
     my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);      }
     my $curRes;      return $ims_manifest;
     my $count = 0;  }
     my $depth = 0;  
     my $lastcontainer = 0;  sub build_package {
     my %parent = ();      my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
     my @dependencies = ();  # first iterator to look for dependencies
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};      my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $curRes;
     while ($curRes = $it->next()) {      my $count = 0;
         if (ref($curRes)) {      my $depth = 0;
             $count ++;      my $lastcontainer = 0;
         }      my %parent = ();
         if ($curRes == $it->BEGIN_MAP()) {      my @dependencies = ();
             $depth++;      my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
             $parent{$depth} = $lastcontainer;      my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         }      while ($curRes = $it->next()) {
         if ($curRes == $it->END_MAP()) {          if (ref($curRes)) {
             $depth--;              $count ++;
             $lastcontainer = $parent{$depth};          }
         }          if ($curRes == $it->BEGIN_MAP()) {
         if (ref($curRes)) {              $depth++;
             if ($curRes->is_sequence() || $curRes->is_page()) {              $parent{$depth} = $lastcontainer;
                 $lastcontainer = $count;          }
             }          if ($curRes == $it->END_MAP()) {
             if (grep(/^$count$/,@$exportitems)) {              $depth--;
                 &get_dependencies($exportitems,\%parent,$depth,\@dependencies);              $lastcontainer = $parent{$depth};
             }          }
         }          if (ref($curRes)) {
     }              if ($curRes->is_sequence() || $curRes->is_page()) {
 # second iterator to build manifest and store resources                  $lastcontainer = $count;
     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);              }
     $depth = 0;              if (grep(/^$count$/,@$exportitems)) {
     my $prevdepth;                  &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
     $count = 0;              }
     my $imsresources;          }
     my $pkgdepth;      }
     while ($curRes = $it->next()) {  # second iterator to build manifest and store resources
         if ($curRes == $it->BEGIN_MAP()) {      $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
             $prevdepth = $depth;      $depth = 0;
             $depth++;      my $prevdepth;
         }      $count = 0;
         if ($curRes == $it->END_MAP()) {      my $imsresources;
             $prevdepth = $depth;      my $pkgdepth;
             $depth--;      while ($curRes = $it->next()) {
         }          if ($curRes == $it->BEGIN_MAP()) {
               $prevdepth = $depth;
         if (ref($curRes)) {              $depth++;
             $count ++;          }
             if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {          if ($curRes == $it->END_MAP()) {
                 my $symb = $curRes->symb();              $prevdepth = $depth;
                 my $isvisible = 'true';              $depth--;
                 my $resourceref;          }
                 if ($curRes->randomout()) {  
                     $isvisible = 'false';          if (ref($curRes)) {
                 }              $count ++;
                 unless ($curRes->is_sequence()) {              if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
                     $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';                  my $symb = $curRes->symb();
                 }                  my $isvisible = 'true';
                 my $step = $prevdepth - $depth;                  my $resourceref;
                 if (($step >= 0) && ($count > 1)) {                  if ($curRes->randomout()) {
                     while ($step >= 0) {                      $isvisible = 'false';
                         print $ims_manifest "\n".'  </item>'."\n";                  }
                         $step --;                  unless ($curRes->is_sequence()) {
                     }                      $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
                 }                  }
                 $prevdepth = $depth;                  my $step = $prevdepth - $depth;
                   if (($step >= 0) && ($count > 1)) {
                 my $itementry =                      while ($step >= 0) {
               '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.                          print $ims_manifest "\n".'  </item>'."\n";
               '" isvisible="'.$isvisible.'" '.$resourceref.'>'.                          $step --;
               '<title>'.$curRes->title().'</title>';                      }
                 print $ims_manifest "\n".$itementry;                  }
                   $prevdepth = $depth;
                 unless ($curRes->is_sequence()) {  
                     my $content_file;                  my $itementry =
                     my @hrefs = ();                '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
                     &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);                '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
                     if ($content_file) {                '<title>'.$curRes->title().'</title>';
                         $imsresources .= "\n".                  print $ims_manifest "\n".$itementry;
                      '   <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.  
                      '" type="webcontent" href="'.$content_file.'">'."\n".                  unless ($curRes->is_sequence()) {
                      '       <file href="'.$content_file.'" />'."\n";                      my $content_file;
                         foreach my $item (@hrefs) {                      my @hrefs = ();
                             $imsresources .=                      &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
                      '        <file href="'.$item.'" />'."\n";                      if ($content_file) {
                         }                          $imsresources .= "\n".
                         if (grep(/^$count$/,@$discussions)) {                       '   <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
                             my $ressymb = $symb;                       '" type="webcontent" href="'.$content_file.'">'."\n".
                             my $mode;                       '       <file href="'.$content_file.'" />'."\n";
                             if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {                          foreach my $item (@hrefs) {
                                 unless ($ressymb =~ m|adm/wrapper/adm|) {                              $imsresources .=
                                     $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';                       '        <file href="'.$item.'" />'."\n";
                                 }                          }
                                 $mode = 'board';                          if (grep(/^$count$/,@$discussions)) {
                             }                              my $ressymb = $symb;
                             my %extras = (                              my $mode;
                                           caller => 'imsexport',                              if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
                                           tempexport => $tempexport.'/resources',                                  unless ($ressymb =~ m|adm/wrapper/adm|) {
                                           count => $count                                      $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                                          );                                  }
                             my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);                                  $mode = 'board';
                         }                              }
                         $imsresources .= '    </resource>'."\n";                              my %extras = (
                     }                                            caller => 'imsexport',
                 }                                            tempexport => $tempexport.'/resources',
                 $pkgdepth = $depth;                                            count => $count
             }                                           );
         }                              my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
     }                          }
     while ($pkgdepth > 0) {                          $imsresources .= '    </resource>'."\n";
         print $ims_manifest "    </item>\n";                      }
         $pkgdepth --;                  }
     }                  $pkgdepth = $depth;
     my $resource_text = qq|              }
     </organization>          }
   </organizations>      }
   <resources>      while ($pkgdepth > 0) {
     $imsresources          print $ims_manifest "    </item>\n";
   </resources>          $pkgdepth --;
 </manifest>      }
     |;      my $resource_text = qq|
     print $ims_manifest $resource_text;      </organization>
 }    </organizations>
     <resources>
 sub get_dependencies {      $imsresources
     my ($exportitems,$parent,$depth,$dependencies) = @_;    </resources>
     if ($depth > 1) {  </manifest>
         if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {      |;
             push(@{$dependencies},$$parent{$depth});      print $ims_manifest $resource_text;
             if ($depth > 2) {  }
                 &get_dependencies($exportitems,$parent,$depth-1,$dependencies);  
             }  sub get_dependencies {
         }      my ($exportitems,$parent,$depth,$dependencies) = @_;
     }      if ($depth > 1) {
 }          if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
               push(@{$dependencies},$$parent{$depth});
 sub process_content {              if ($depth > 2) {
     my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;                  &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
     my $content_type;              }
     my $message;          }
     my @uploads = ();      }
     if ($curRes->is_sequence()) {  }
         $content_type = 'sequence';  
     } elsif ($curRes->is_page()) {  sub process_content {
         $content_type = 'page'; # need to handle individual items in pages.      my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
     } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {      my $content_type;
         $content_type = 'syllabus';      my $message;
         my $contents = &Apache::imsexport::templatedpage($content_type);      my @uploads = ();
         if ($contents) {      if ($curRes->is_sequence()) {
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);          $content_type = 'sequence';
         }      } elsif ($curRes->is_page()) {
     } elsif ($symb =~ m-\.sequence___\d+___ext-) {          $content_type = 'page'; # need to handle individual items in pages.
         $content_type = 'external';      } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
         my $title = $curRes->title;          $content_type = 'syllabus';
         my $contents =  &Apache::imsexport::external($symb,$title);          my $contents = &Apache::imsexport::templatedpage($content_type);
         if ($contents) {          if ($contents) {
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
         }          }
     } elsif ($symb =~ m-adm/navmaps$-) {      } elsif ($symb =~ m-\.sequence___\d+___ext-) {
         $content_type =  'navmap';          $content_type = 'external';
     } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {          my $title = $curRes->title;
         $content_type = 'simplepage';          my $contents =  &Apache::imsexport::external($symb,$title);
         my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);          if ($contents) {
         if ($contents) {              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);          }
         }      } elsif ($symb =~ m-adm/navmaps$-) {
     } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {          $content_type =  'navmap';
         $content_type = 'simpleproblem';      } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
         my $contents =  &Apache::imsexport::simpleproblem($symb);          $content_type = 'simplepage';
         if ($contents) {          my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);          if ($contents) {
         }              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
     } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {          }
         $content_type = 'examupload';      } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
     } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {          $content_type = 'simpleproblem';
         $content_type = 'bulletinboard';          my $contents =  &Apache::imsexport::simpleproblem($symb);
         my $contents =  &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);          if ($contents) {
         if ($contents) {              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);          }
         }      } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
     } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {          $content_type = 'examupload';
         $content_type = 'aboutme';      } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
         my $contents =  &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);          $content_type = 'bulletinboard';
         if ($contents) {          my $contents =  &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);          if ($contents) {
         }              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
     } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {          }
         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');      } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
     } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {          $content_type = 'aboutme';
         my $canedit = 0;          my $contents =  &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
         if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'})  {          if ($contents) {
             $canedit= 1;              $$content_file = &store_template($contents,$tempexport,$count,$content_type);
         }          }
 # only include problem code where current user is author      } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
         if ($canedit) {          $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');      } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
         } else {          my $canedit = 0;
             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');          if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'})  {
         }              $canedit= 1;
     } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {          }
         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');  # only include problem code where current user is author
     }          if ($canedit) {
     if (@uploads > 0) {              $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
         foreach my $item (@uploads) {          } else {
             my $uploadmsg = '';              $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
             &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');          }
             if ($uploadmsg) {      } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
                 $$copyresult .= $uploadmsg."\n";          $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
             }      }
         }      if (@uploads > 0) {
     }          foreach my $item (@uploads) {
     if ($message) {              my $uploadmsg = '';
         $$copyresult .= $message."\n";              &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
     }              if ($uploadmsg) {
 }                  $$copyresult .= $uploadmsg."\n";
               }
 sub replicate_content {          }
     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;      }
     my ($map,$ind,$url);      if ($message) {
     if ($caller eq 'templateupload') {          $$copyresult .= $message."\n";
         $url = $symb;      }
         $url =~ s#//#/#g;  }
     } else {   
         ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);  sub replicate_content {
     }      my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
     my $content;      my ($map,$ind,$url);
     my $filename;      if ($caller eq 'templateupload') {
     my $repstatus;          $url = $symb;
     my $content_name;          $url =~ s#//#/#g;
     if ($url =~ m-/([^/]+)$-) {      } else {
         $filename = $1;          ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
         if (!-e $tempexport.'/resources') {      }
             mkdir($tempexport.'/resources',0700);      my $content;
         }      my $filename;
         if (!-e $tempexport.'/resources/'.$count) {      my $repstatus;
             mkdir($tempexport.'/resources/'.$count,0700);      my $content_name;
         }      if ($url =~ m-/([^/]+)$-) {
         my $destination = $tempexport.'/resources/'.$count.'/'.$filename;          $filename = $1;
         my $copiedfile;          if (!-e $tempexport.'/resources') {
         if ($copiedfile = Apache::File->new('>'.$destination)) {              mkdir($tempexport.'/resources',0700);
             my $content;          }
             if ($caller eq 'resource') {          if (!-e $tempexport.'/resources/'.$count) {
                 my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';              mkdir($tempexport.'/resources/'.$count,0700);
                 my $filepath = &Apache::lonnet::filelocation($respath,$url);          }
                 $content = &Apache::lonnet::getfile($filepath);          my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
                 if ($content eq -1) {          my $copiedfile;
                     $$message = 'Could not copy file '.$filename;          if ($copiedfile = Apache::File->new('>'.$destination)) {
                 } else {              my $content;
                     &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');              if ($caller eq 'resource') {
                     $repstatus = 'ok';                  my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
                 }                  my $filepath = &Apache::lonnet::filelocation($respath,$url);
             } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {                  $content = &Apache::lonnet::getfile($filepath);
                 my $rtncode;                  if ($content eq -1) {
                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);                      $$message = 'Could not copy file '.$filename;
                 if ($repstatus eq 'ok') {                  } else {
                     if ($url =~ /\.html?$/i) {                      &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
                         &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');                      $repstatus = 'ok';
                     }                  }
                 } else {              } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
                     $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";                  my $rtncode;
                 }                  $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
             } elsif ($caller eq 'noedit') {                  if ($repstatus eq 'ok') {
 # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.                       if ($url =~ /\.html?$/i) {
                 $repstatus = 'ok';                          &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
                 $content = 'Not the owner of this resource';                       }
             }                  } else {
             if ($repstatus eq 'ok') {                      $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
                 print $copiedfile $content;                  }
             }              } elsif ($caller eq 'noedit') {
             close($copiedfile);  # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
         } else {                  $repstatus = 'ok';
             $$message = 'Could not open destination file for '.$filename."<br />\n";                  $content = 'Not the owner of this resource';
         }              }
     } else {              if ($repstatus eq 'ok') {
         $$message = 'Could not determine name of file for '.$symb."<br />\n";                  print $copiedfile $content;
     }              }
     if ($repstatus eq 'ok') {              close($copiedfile);
         $content_name = 'resources/'.$count.'/'.$filename;          } else {
     }              $$message = 'Could not open destination file for '.$filename."<br />\n";
     return $content_name;          }
 }      } else {
           $$message = 'Could not determine name of file for '.$symb."<br />\n";
 sub extract_media {      }
     my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;      if ($repstatus eq 'ok') {
     my ($dirpath,$container);          $content_name = 'resources/'.$count.'/'.$filename;
     my %allfiles = ();      }
     my %codebase = ();      return $content_name;
     if ($url =~ m-(.*/)([^/]+)$-) {  }
         $dirpath = $1;  
         $container = $2;  sub extract_media {
     } else {      my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
         $dirpath = $url;      my ($dirpath,$container);
         $container = '';      my %allfiles = ();
     }      my %codebase = ();
     &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);      if ($url =~ m-(.*/)([^/]+)$-) {
     foreach my $embed_file (keys(%allfiles)) {          $dirpath = $1;
         my $filename;          $container = $2;
         if ($embed_file =~ m#([^/]+)$#) {      } else {
             $filename = $1;          $dirpath = $url;
         } else {          $container = '';
             $filename = $embed_file;      }
         }      &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
         my $newname = 'res/'.$filename;      foreach my $embed_file (keys(%allfiles)) {
         my ($rtncode,$embed_content,$repstatus);          my $filename;
         my $embed_url;          if ($embed_file =~ m#([^/]+)$#) {
         if ($embed_file =~ m-^/-) {              $filename = $1;
             $embed_url = $embed_file;           # points to absolute path          } else {
         } else {              $filename = $embed_file;
             if ($embed_file =~ m-https?://-) {          }
                 next;                           # points to url          my $newname = 'res/'.$filename;
             } else {          my ($rtncode,$embed_content,$repstatus);
                 $embed_url = $dirpath.$embed_file;  # points to relative path          my $embed_url;
             }          if ($embed_file =~ m-^/-) {
         }              $embed_url = $embed_file;           # points to absolute path
         if ($caller eq 'resource') {          } else {
             my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';                if ($embed_file =~ m-https?://-) {
             my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);                   next;                           # points to url
             $embed_content = &Apache::lonnet::getfile($embed_path);              } else {
             unless ($embed_content eq -1) {                  $embed_url = $dirpath.$embed_file;  # points to relative path
                 $repstatus = 'ok';              }
             }          }
         } elsif ($caller eq 'uploaded') {          if ($caller eq 'resource') {
                           my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';  
             $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);              my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
         }              $embed_content = &Apache::lonnet::getfile($embed_path);
         if ($repstatus eq 'ok') {              unless ($embed_content eq -1) {
             my $destination = $tempexport.'/resources/'.$count.'/res';                  $repstatus = 'ok';
             if (!-e "$destination") {              }
                 mkdir($destination,0755);          } elsif ($caller eq 'uploaded') {
             }             
             $destination .= '/'.$filename;              $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
             my $copiedfile;          }
             if ($copiedfile = Apache::File->new('>'.$destination)) {          if ($repstatus eq 'ok') {
                 print $copiedfile $embed_content;              my $destination = $tempexport.'/resources/'.$count.'/res';
                 push(@{$href},'resources/'.$count.'/res/'.$filename);              if (!-e "$destination") {
                 my $attrib_regexp = '';                  mkdir($destination,0755);
                 if (@{$allfiles{$embed_file}} > 1) {              }
                     $attrib_regexp = join('|',@{$allfiles{$embed_file}});              $destination .= '/'.$filename;
                 } else {              my $copiedfile;
                     $attrib_regexp = $allfiles{$embed_file}[0];              if ($copiedfile = Apache::File->new('>'.$destination)) {
                 }                  print $copiedfile $embed_content;
                 $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;                  push(@{$href},'resources/'.$count.'/res/'.$filename);
                 if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {                  my $attrib_regexp = '';
                     $$content =~ s#\Q$embed_file\E#$newname#gi;                  if (@{$allfiles{$embed_file}} > 1) {
                 }                      $attrib_regexp = join('|',@{$allfiles{$embed_file}});
             }                  } else {
         } else {                      $attrib_regexp = $allfiles{$embed_file}[0];
             $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";                  }
         }                  $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
     }                  if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
     return;                      $$content =~ s#\Q$embed_file\E#$newname#gi;
 }                  }
               }
 sub store_template {          } else {
     my ($contents,$tempexport,$count,$content_type) = @_;              $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
     if ($contents) {          }
         if ($tempexport) {      }
             if (!-e $tempexport.'/resources') {      return;
                 mkdir($tempexport.'/resources',0700);  }
             }  
             if (!-e $tempexport.'/resources/'.$count) {  sub store_template {
                 mkdir($tempexport.'/resources/'.$count,0700);      my ($contents,$tempexport,$count,$content_type) = @_;
             }      if ($contents) {
             my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';          if ($tempexport) {
             my $storetemplate;              if (!-e $tempexport.'/resources') {
             if ($storetemplate = Apache::File->new('>'.$destination)) {                  mkdir($tempexport.'/resources',0700);
                 print $storetemplate $contents;              }
                 close($storetemplate);              if (!-e $tempexport.'/resources/'.$count) {
             }                  mkdir($tempexport.'/resources/'.$count,0700);
             if ($content_type eq 'external') {              }
                 return 'resources/'.$count.'/'.$content_type.'.html';              my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
             } else {              my $storetemplate;
                 return 'resources/'.$count.'/'.$content_type.'.xml';              if ($storetemplate = Apache::File->new('>'.$destination)) {
             }                  print $storetemplate $contents;
         }                  close($storetemplate);
     }              }
 }              if ($content_type eq 'external') {
                   return 'resources/'.$count.'/'.$content_type.'.html';
               } else {
 sub group_import {                  return 'resources/'.$count.'/'.$content_type.'.xml';
     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;              }
           }
     while (@files) {      }
  my ($name, $url, $residx) = @{ shift(@files) };  }
         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})   
      && ($caller eq 'londocs')  
      && (!&Apache::lonnet::stat_file($url))) {  sub group_import {
           my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
             my $errtext = '';  
             my $fatal = 0;      while (@files) {
             my $newmapstr = '<map>'."\n".   my ($name, $url, $residx) = @{ shift(@files) };
                             '<resource id="1" src="" type="start"></resource>'."\n".          if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
                             '<link from="1" to="2" index="1"></link>'."\n".       && ($caller eq 'londocs')
                             '<resource id="2" src="" type="finish"></resource>'."\n".       && (!&Apache::lonnet::stat_file($url))) {
                             '</map>';      
             $env{'form.output'}=$newmapstr;              my $errtext = '';
             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,              my $fatal = 0;
                                                 'output',$1.$2);              my $newmapstr = '<map>'."\n".
             if ($result != m|^/uploaded/|) {                              '<resource id="1" src="" type="start"></resource>'."\n".
                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';                              '<link from="1" to="2" index="1"></link>'."\n".
                 $fatal = 2;                              '<resource id="2" src="" type="finish"></resource>'."\n".
             }                              '</map>';
             if ($fatal) {              $env{'form.output'}=$newmapstr;
                 return ($errtext,$fatal);              my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
             }                                                  'output',$1.$2);
         }              if ($result != m|^/uploaded/|) {
  if ($url) {                  $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
     if (!$residx                   $fatal = 2;
  || defined($LONCAPA::map::zombies[$residx])) {              }
  $residx = &LONCAPA::map::getresidx($url,$residx);              if ($fatal) {
  push(@LONCAPA::map::order, $residx);                  return ($errtext,$fatal);
     }              }
     my $ext = 'false';          }
     if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }   if ($url) {
     $url  = &LONCAPA::map::qtunescape($url);      if (!$residx
     $name = &LONCAPA::map::qtunescape($name);   || defined($LONCAPA::map::zombies[$residx])) {
     $LONCAPA::map::resources[$residx] =    $residx = &LONCAPA::map::getresidx($url,$residx);
  join(':', ($name, $url, $ext, 'normal', 'res'));   push(@LONCAPA::map::order, $residx);
  }      }
     }      my $ext = 'false';
     return &storemap($coursenum, $coursedom, $folder.'.'.$container);      if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
 }      $url  = &LONCAPA::map::qtunescape($url);
       $name = &LONCAPA::map::qtunescape($name);
 sub breadcrumbs {      $LONCAPA::map::resources[$residx] =
     my ($where,$allowed,$type)=@_;   join(':', ($name, $url, $ext, 'normal', 'res'));
     &Apache::lonhtmlcommon::clear_breadcrumbs();   }
     my (@folders);      }
     if ($env{'form.pagepath'}) {      return &storemap($coursenum, $coursedom, $folder.'.'.$container);
         @folders = split('&',$env{'form.pagepath'});  }
     } else {  
         @folders=split('&',$env{'form.folderpath'});  sub breadcrumbs {
     }      my ($where,$allowed,$type)=@_;
     my $folderpath;      &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $cpinfo='';      my (@folders);
     my $plain='';      if ($env{'form.pagepath'}) {
     my $randompick=-1;          @folders = split('&',$env{'form.pagepath'});
     my $isencrypted=0;      } else {
     my $ishidden=0;          @folders=split('&',$env{'form.folderpath'});
     my $is_random_order=0;      }
     while (@folders) {      my $folderpath;
  my $folder=shift(@folders);      my $cpinfo='';
     my $foldername=shift(@folders);      my $plain='';
  if ($folderpath) {$folderpath.='&';}      my $randompick=-1;
  $folderpath.=$folder.'&'.$foldername;      my $isencrypted=0;
  my $url='/adm/coursedocs?folderpath='.      my $ishidden=0;
     &escape($folderpath);      my $is_random_order=0;
     my $name=&unescape($foldername);      while (@folders) {
 # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername   my $folder=shift(@folders);
      $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;      my $foldername=shift(@folders);
     if ($1 ne '') {    if ($folderpath) {$folderpath.='&';}
                $randompick=$1;   $folderpath.=$folder.'&'.$foldername;
             } else {   my $url='/adm/coursedocs?folderpath='.
                $randompick=-1;      &escape($folderpath);
             }      my $name=&unescape($foldername);
             if ($2) { $ishidden=1; }  # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
             if ($3) { $isencrypted=1; }       $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
     if ($4 ne '') { $is_random_order = 1; }      if ($1 ne '') {
             if ($folder eq 'supplemental') {                 $randompick=$1;
                 if ($allowed) {              } else {
                     $name = &mt('Supplemental '.$type.' Documents');                 $randompick=-1;
                 } else {              }
                     $name = &mt($type.' Documents');              if ($2) { $ishidden=1; }
                 }              if ($3) { $isencrypted=1; }
             }      if ($4 ne '') { $is_random_order = 1; }
     &Apache::lonhtmlcommon::add_breadcrumb(              if ($folder eq 'supplemental') {
       {'href'=>$url.$cpinfo,                  if ($allowed) {
        'title'=>$name,                      $name = &mt('Supplemental '.$type.' Documents');
        'text'=>'<font size="+1">'.                  } else {
    $name.'</font>',                      $name = &mt($type.' Documents');
        'no_mt'=>1,                  }
        });              }
  $plain.=$name.' &gt; ';      &Apache::lonhtmlcommon::add_breadcrumb(
     }        {'href'=>$url.$cpinfo,
     $plain=~s/\&gt\;\s*$//;         'title'=>$name,
     return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',         'text'=>'<font size="+1">'.
        'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);     $name.'</font>',
 }         'no_mt'=>1,
          });
 sub log_docs {   $plain.=$name.' &gt; ';
     return &Apache::lonnet::instructor_log('docslog',@_);      }
 }      $plain=~s/\&gt\;\s*$//;
       return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
 {         'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
     my @oldresources=();  }
     my @oldorder=();  
     my $parmidx;  sub log_docs {
     my %parmaction=();      return &Apache::lonnet::instructor_log('docslog',@_);
     my %parmvalue=();  }
     my $changedflag;  
   {
     sub snapshotbefore {      my @oldresources=();
         @oldresources=@LONCAPA::map::resources;      my @oldorder=();
         @oldorder=@LONCAPA::map::order;      my $parmidx;
         $parmidx=undef;      my %parmaction=();
         %parmaction=();      my %parmvalue=();
         %parmvalue=();      my $changedflag;
         $changedflag=0;  
     }      sub snapshotbefore {
           @oldresources=@LONCAPA::map::resources;
     sub remember_parms {          @oldorder=@LONCAPA::map::order;
         my ($idx,$parameter,$action,$value)=@_;          $parmidx=undef;
         $parmidx=$idx;          %parmaction=();
         $parmaction{$parameter}=$action;          %parmvalue=();
         $parmvalue{$parameter}=$value;          $changedflag=0;
         $changedflag=1;      }
     }  
       sub remember_parms {
     sub log_differences {          my ($idx,$parameter,$action,$value)=@_;
         my ($plain)=@_;          $parmidx=$idx;
         my %storehash=('folder' => $plain,          $parmaction{$parameter}=$action;
                        'currentfolder' => $env{'form.folder'});          $parmvalue{$parameter}=$value;
         if ($parmidx) {          $changedflag=1;
            $storehash{'parameter_res'}=$oldresources[$parmidx];      }
            foreach my $parm (keys(%parmaction)) {  
               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};      sub log_differences {
               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};          my ($plain)=@_;
            }          my %storehash=('folder' => $plain,
         }                         'currentfolder' => $env{'form.folder'});
         my $maxidx=$#oldresources;          if ($parmidx) {
         if ($#LONCAPA::map::resources>$#oldresources) {             $storehash{'parameter_res'}=$oldresources[$parmidx];
            $maxidx=$#LONCAPA::map::resources;             foreach my $parm (keys(%parmaction)) {
         }                $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
         for (my $idx=0; $idx<=$maxidx; $idx++) {                $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {             }
               $storehash{'before_resources_'.$idx}=$oldresources[$idx];          }
               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];          my $maxidx=$#oldresources;
               $changedflag=1;          if ($#LONCAPA::map::resources>$#oldresources) {
            }             $maxidx=$#LONCAPA::map::resources;
            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {          }
               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];          for (my $idx=0; $idx<=$maxidx; $idx++) {
               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];             if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
               $changedflag=1;                $storehash{'before_resources_'.$idx}=$oldresources[$idx];
            }                $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
         }                $changedflag=1;
  $storehash{'maxidx'}=$maxidx;             }
         if ($changedflag) { &log_docs(\%storehash); }             if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
     }                $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
 }                $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                 $changedflag=1;
              }
           }
    $storehash{'maxidx'}=$maxidx;
           if ($changedflag) { &log_docs(\%storehash); }
 sub docs_change_log {      }
     my ($r)=@_;  }
     my $folder=$env{'form.folder'};  
     $r->print(&Apache::loncommon::start_page('Course Document Change Log'));  
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));  
     my %docslog=&Apache::lonnet::dump('nohist_docslog',  
                                       $env{'course.'.$env{'request.course.id'}.'.domain'},  
                                       $env{'course.'.$env{'request.course.id'}.'.num'});  sub docs_change_log {
       my ($r)=@_;
     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }      my $folder=$env{'form.folder'};
       $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
     $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
               '<input type="hidden" name="docslog" value="1" />');      my %docslog=&Apache::lonnet::dump('nohist_docslog',
                                         $env{'course.'.$env{'request.course.id'}.'.domain'},
     my %saveable_parameters = ('show' => 'scalar',);                                        $env{'course.'.$env{'request.course.id'}.'.num'});
     &Apache::loncommon::store_course_settings('docs_log',  
                                               \%saveable_parameters);      if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
     &Apache::loncommon::restore_course_settings('docs_log',  
                                                 \%saveable_parameters);      $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
     if (!$env{'form.show'}) { $env{'form.show'}=10; }                '<input type="hidden" name="docslog" value="1" />');
     my %lt=('hiddenresource' => 'Resources hidden',  
     'encrypturl'     => 'URL hidden',      my %saveable_parameters = ('show' => 'scalar',);
     'randompick'     => 'Randomly pick',      &Apache::loncommon::store_course_settings('docs_log',
     'randomorder'    => 'Randomly ordered',                                                \%saveable_parameters);
     'set'            => 'set to',      &Apache::loncommon::restore_course_settings('docs_log',
     'del'            => 'deleted');                                                  \%saveable_parameters);
     $r->print(&Apache::loncommon::display_filter().      if (!$env{'form.show'}) { $env{'form.show'}=10; }
               '<input type="hidden" name="folder" value="'.$folder.'" />'.      my %lt=('hiddenresource' => 'Resources hidden',
               '<input type="submit" value="'.&mt('Display').'" /></form>');      'encrypturl'     => 'URL hidden',
     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().      'randompick'     => 'Randomly pick',
               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.      'randomorder'    => 'Randomly ordered',
               &mt('After').'</th>'.      'set'            => 'set to',
               &Apache::loncommon::end_data_table_header_row());      'del'            => 'deleted');
     my $shown=0;      $r->print(&Apache::loncommon::display_filter().
     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {                '<input type="hidden" name="folder" value="'.$folder.'" />'.
  if ($env{'form.displayfilter'} eq 'currentfolder') {                '<input type="submit" value="'.&mt('Display').'" /></form>');
     if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }      $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
  }                '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
         my @changes=keys(%{$docslog{$id}{'logentry'}});                &mt('After').'</th>'.
         if ($env{'form.displayfilter'} eq 'containing') {                &Apache::loncommon::end_data_table_header_row());
     my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.      my $shown=0;
  &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});      foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
     foreach my $key (@changes) {   if ($env{'form.displayfilter'} eq 'currentfolder') {
  $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};      if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
     }   }
     if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }                   my @changes=keys(%{$docslog{$id}{'logentry'}});
  }          if ($env{'form.displayfilter'} eq 'containing') {
         my $count = 0;      my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
         my $time =   &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});      foreach my $key (@changes) {
         my $plainname =   $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},      }
                                           $docslog{$id}{'exe_udom'});      if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }        
         my $about_me_link =   }
             &Apache::loncommon::aboutmewrapper($plainname,          my $count = 0;
                                                $docslog{$id}{'exe_uname'},          my $time =
                                                $docslog{$id}{'exe_udom'});              &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
         my $send_msg_link='';          my $plainname =
         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})              &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {                                            $docslog{$id}{'exe_udom'});
             $send_msg_link ='<br />'.          my $about_me_link =
                 &Apache::loncommon::messagewrapper(&mt('Send message'),              &Apache::loncommon::aboutmewrapper($plainname,
                                                    $docslog{$id}{'exe_uname'},                                                 $docslog{$id}{'exe_uname'},
                                                    $docslog{$id}{'exe_udom'});                                                 $docslog{$id}{'exe_udom'});
         }          my $send_msg_link='';
         $r->print(&Apache::loncommon::start_data_table_row());          if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
         $r->print('<td>'.$time.'</td>               || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                        <td>'.$about_me_link.              $send_msg_link ='<br />'.
                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.                  &Apache::loncommon::messagewrapper(&mt('Send message'),
                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.                                                     $docslog{$id}{'exe_uname'},
                   $send_msg_link.'</td><td>'.                                                     $docslog{$id}{'exe_udom'});
                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');          }
 # Before          $r->print(&Apache::loncommon::start_data_table_row());
  for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {          $r->print('<td>'.$time.'</td>
     my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];                         <td>'.$about_me_link.
     my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];                    '<br /><tt>'.$docslog{$id}{'exe_uname'}.
     if ($oldname ne $newname) {                                    ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
  $r->print(&LONCAPA::map::qtescape($oldname));                    $send_msg_link.'</td><td>'.
     }                    $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
  }  # Before
  $r->print('<ul>');   for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
  for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {      my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {      my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
  $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');      if ($oldname ne $newname) {
     }   $r->print(&LONCAPA::map::qtescape($oldname));
  }      }
  $r->print('</ul>');   }
 # After   $r->print('<ul>');
         $r->print('</td><td>');   for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
               if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
  for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {   $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
     my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];      }
     my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];   }
     if ($oldname ne '' && $oldname ne $newname) {   $r->print('</ul>');
  $r->print(&LONCAPA::map::qtescape($newname));  # After
     }          $r->print('</td><td>');
  }          
  $r->print('<ul>');   for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
  for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {      my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {      my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
  $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');      if ($oldname ne '' && $oldname ne $newname) {
     }   $r->print(&LONCAPA::map::qtescape($newname));
  }      }
  $r->print('</ul>');   }        
  if ($docslog{$id}{'logentry'}{'parameter_res'}) {   $r->print('<ul>');
     $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');   for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
     foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {              if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
  if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {   $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
     $r->print('<li>'.      }
       &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',   }
   $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})   $r->print('</ul>');
       .'</li>');   if ($docslog{$id}{'logentry'}{'parameter_res'}) {
  }      $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
     }      foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
     $r->print('</ul>');   if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
  }      $r->print('<li>'.
 # End        &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
         $r->print('</td>'.&Apache::loncommon::end_data_table_row());    $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
         $shown++;        .'</li>');
         if (!($env{'form.show'} eq &mt('all')   }
               || $shown<=$env{'form.show'})) { last; }      }
     }      $r->print('</ul>');
     $r->print(&Apache::loncommon::end_data_table());   }
 }  # End
           $r->print('</td>'.&Apache::loncommon::end_data_table_row());
 sub update_paste_buffer {          $shown++;
     my ($coursenum,$coursedom) = @_;          if (!($env{'form.show'} eq &mt('all')
                 || $shown<=$env{'form.show'})) { last; }
     return if (!defined($env{'form.markcopy'}));      }
     return if (!defined($env{'form.copyfolder'}));      $r->print(&Apache::loncommon::end_data_table());
     return if ($env{'form.markcopy'} < 0);  }
   
     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,  sub update_paste_buffer {
     $env{'form.copyfolder'});      my ($coursenum,$coursedom) = @_;
       
     return if ($fatal);      return if (!defined($env{'form.markcopy'}));
       return if (!defined($env{'form.copyfolder'}));
 # Mark for copying      return if ($env{'form.markcopy'} < 0);
     my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);  
     if (&is_supplemental_title($title)) {      my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
         &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});      $env{'form.copyfolder'});
  ($title) = &parse_supplemental_title($title);     
     } elsif ($env{'docs.markedcopy_supplemental'}) {      return if ($fatal);
         &Apache::lonnet::delenv('docs\\.markedcopy_supplemental');  
     }  # Mark for copying
     $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};      my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
       if (&is_supplemental_title($title)) {
     &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,          &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
     'docs.markedcopy_url'   => $url});   ($title) = &parse_supplemental_title($title);
     delete($env{'form.markcopy'});      } elsif ($env{'docs.markedcopy_supplemental'}) {
 }          &Apache::lonnet::delenv('docs\\.markedcopy_supplemental');
       }
 sub print_paste_buffer {      $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
     my ($r,$container) = @_;  
     return if (!defined($env{'docs.markedcopy_url'}));      &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
       'docs.markedcopy_url'   => $url});
     $r->print(<<ENDPASTE);      delete($env{'form.markcopy'});
 <form name="pasteform" action="/adm/coursedocs" method="post"><p>  }
 ENDPASTE  
     $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');  sub print_paste_buffer {
       my ($r,$container) = @_;
     my $type;      return if (!defined($env{'docs.markedcopy_url'}));
     if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {  
  $type = &mt('External Resource');      $r->print(<<ENDPASTE);
  $r->print($type.': '.  <form name="pasteform" action="/adm/coursedocs" method="post"><p>
   &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.  ENDPASTE
   &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');      $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
     }  else {  
  my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];      my $type;
  my $icon = &Apache::loncommon::icon($extension);      if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
  if ($extension eq 'sequence' &&   $type = &mt('External Resource');
     $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {   $r->print($type.': '.
     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));    &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
     $icon .= '/folder_closed.gif';    &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
  }      }  else {
  $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';   my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
  $r->print($icon.$type.': '.  &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));   my $icon = &Apache::loncommon::icon($extension);
     }   if ($extension eq 'sequence' &&
     if ($container eq 'page') {      $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
  $r->print('      $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
  <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />      $icon .= '/folder_closed.gif';
  <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />   }
 ');   $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
     } else {   $r->print($icon.$type.': '.  &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
  $r->print('      }
         <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />      if ($container eq 'page') {
 ');   $r->print('
     }   <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
     $r->print('</p></form>');   <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
 }  ');
       } else {
 sub do_paste_from_buffer {   $r->print('
     my ($coursenum,$coursedom,$folder) = @_;          <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
   ');
     if (!$env{'form.pastemarked'}) {      }
         return;      $r->print('</p></form>');
     }  }
   
 # paste resource to end of list  sub do_paste_from_buffer {
     my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});      my ($coursenum,$coursedom,$folder) = @_;
     my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});  
 # Maps need to be copied first      if (!$env{'form.pastemarked'}) {
     if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {          return;
  $title=&mt('Copy of').' '.$title;      }
  my $newid=$$.time;  
  $url=~/^(.+)\.(\w+)$/;  # paste resource to end of list
  my $newurl=$1.$newid.'.'.$2;      my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
  my $storefn=$newurl;      my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
  $storefn=~s{^/\w+/$match_domain/$match_username/}{};  # Maps need to be copied first
  my $paste_map_result =      if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
             &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,   $title=&mt('Copy of').' '.$title;
        &Apache::lonnet::getfile($url));   my $newid=$$.int(rand(100)).time;
         if ($paste_map_result eq '/adm/notfound.html') {   my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
             if ($url=~/\.page$/) {          if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
                 return &mt('Paste failed: an error occurred saving the composite page');              my $path = $1;
             } else {              my $prefix = $2;
                 return &mt('Paste failed: an error occurred saving the folder');              my $ancestor = $3;
             }              if (length($ancestor) > 10) {
         }                  $ancestor = substr($ancestor,-10,10);
  $url = $newurl;              }
     }              $oldid = $path.$prefix.$ancestor;
 # published maps can only exists once, so remove it from paste buffer when done          }
     if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {          my $counter = 0;
  &Apache::lonnet::delenv('docs\\.markedcopy');          my $newurl=$oldid.$newid.'.'.$ext;
     }          my $is_unique = &uniqueness_check($newurl);
     if ($url=~ m{/smppg$}) {          while (!$is_unique && $counter < 100) {
  my $db_name = &Apache::lonsimplepage::get_db_name($url);              $counter ++;
  if ($db_name =~ /^smppage_/) {              $newid ++;
     #simple pages, need to copy the db contents to a new one.              $newurl = $oldid.$newid;
     my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);              $is_unique = &uniqueness_check($newurl);
     my $now = time();          }
     $db_name =~ s{_\d*$ }{_$now}x;          if (!$is_unique) {
     my $result=&Apache::lonnet::put($db_name,\%contents,              if ($url=~/\.page$/) {
     $coursedom,$coursenum);                  return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
     $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;               } else {
     $title=&mt('Copy of').' '.$title;                  return &mt('Paste failed: an error occurred creating a unique URL for the folder');
  }              }
     }          }
     $title = &LONCAPA::map::qtunescape($title);   my $storefn=$newurl;
     my $ext='false';   $storefn=~s{^/\w+/$match_domain/$match_username/}{};
     if ($url=~m{^http(|s)://}) { $ext='true'; }   my $paste_map_result =
     $url       = &LONCAPA::map::qtunescape($url);              &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
 # Now insert the URL at the bottom         &Apache::lonnet::getfile($url));
     my $newidx = &LONCAPA::map::getresidx($url);          if ($paste_map_result eq '/adm/notfound.html') {
     if ($env{'docs.markedcopy_supplemental'}) {              if ($url=~/\.page$/) {
         if ($folder =~ /^supplemental/) {                  return &mt('Paste failed: an error occurred saving the composite page');
             $title = $env{'docs.markedcopy_supplemental'};              } else {
         } else {                  return &mt('Paste failed: an error occurred saving the folder');
             (undef,undef,$title) =               }
                 &parse_supplemental_title($env{'docs.markedcopy_supplemental'});          }
         }   $url = $newurl;
     } else {      }
         if ($folder=~/^supplemental/) {  # published maps can only exists once, so remove it from paste buffer when done
            $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.      if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
                   $env{'user.domain'}.'___&&&___'.$title;   &Apache::lonnet::delenv('docs\\.markedcopy');
         }      }
     }      if ($url=~ m{/smppg$}) {
    my $db_name = &Apache::lonsimplepage::get_db_name($url);
     $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';   if ($db_name =~ /^smppage_/) {
     push(@LONCAPA::map::order, $newidx);      #simple pages, need to copy the db contents to a new one.
     return 'ok';      my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
 # Store the result      my $now = time();
 }      $db_name =~ s{_\d*$ }{_$now}x;
       my $result=&Apache::lonnet::put($db_name,\%contents,
 my %parameter_type = ( 'randompick'     => 'int_pos',      $coursedom,$coursenum);
        'hiddenresource' => 'string_yesno',      $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
        'encrypturl'     => 'string_yesno',      $title=&mt('Copy of').' '.$title;
        'randomorder'    => 'string_yesno',);   }
 my $valid_parameters_re = join('|',keys(%parameter_type));      }
 # set parameters      $title = &LONCAPA::map::qtunescape($title);
 sub update_parameter {      my $ext='false';
       if ($url=~m{^http(|s)://}) { $ext='true'; }
     return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);      $url       = &LONCAPA::map::qtunescape($url);
   # Now insert the URL at the bottom
     my $which = $env{'form.changeparms'};      my $newidx = &LONCAPA::map::getresidx($url);
     my $idx = $env{'form.setparms'};      if ($env{'docs.markedcopy_supplemental'}) {
     if ($env{'form.'.$which.'_'.$idx}) {          if ($folder =~ /^supplemental/) {
  my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}              $title = $env{'docs.markedcopy_supplemental'};
                                      : 'yes';          } else {
  &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,              (undef,undef,$title) =
       $parameter_type{$which});                  &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
  &remember_parms($idx,$which,'set',$value);          }
     } else {      } else {
  &LONCAPA::map::delparameter($idx,'parameter_'.$which);          if ($folder=~/^supplemental/) {
              $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
  &remember_parms($idx,$which,'del');                    $env{'user.domain'}.'___&&&___'.$title;
     }          }
     return 1;      }
 }  
       $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
       push(@LONCAPA::map::order, $newidx);
 sub handle_edit_cmd {      return 'ok';
     my ($coursenum,$coursedom) =@_;  # Store the result
   }
     my ($cmd,$idx)=split('_',$env{'form.cmd'});  
   sub uniqueness_check {
     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];      my ($newurl) = @_;
     my ($title, $url, @rrest) = split(':', $ratstr);      my $unique = 1;
       foreach my $res (@LONCAPA::map::order) {
     if ($cmd eq 'del') {          my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
  if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&          $url=&LONCAPA::map::qtescape($url);
     ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {          if ($newurl eq $url) {
     &Apache::lonnet::removeuploadedurl($url);              $unique = 0;
  } else {              last;    
     &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);          }
  }      }
  splice(@LONCAPA::map::order, $idx, 1);      return $unique;
   }
     } elsif ($cmd eq 'cut') {  
  &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);  my %parameter_type = ( 'randompick'     => 'int_pos',
  splice(@LONCAPA::map::order, $idx, 1);         'hiddenresource' => 'string_yesno',
          'encrypturl'     => 'string_yesno',
     } elsif ($cmd eq 'up'          'randomorder'    => 'string_yesno',);
      && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {  my $valid_parameters_re = join('|',keys(%parameter_type));
  @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];  # set parameters
   sub update_parameter {
     } elsif ($cmd eq 'down'  
      && defined($LONCAPA::map::order[$idx+1])) {      return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
  @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];  
       my $which = $env{'form.changeparms'};
     } elsif ($cmd eq 'rename') {      my $idx = $env{'form.setparms'};
       if ($env{'form.'.$which.'_'.$idx}) {
  my $comment = &LONCAPA::map::qtunescape($env{'form.title'});   my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
  if ($comment=~/\S/) {                                       : 'yes';
     $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=   &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
  $comment.':'.join(':', $url, @rrest);        $parameter_type{$which});
  }   &remember_parms($idx,$which,'set',$value);
 # Devalidate title cache      } else {
  my $renamed_url=&LONCAPA::map::qtescape($url);   &LONCAPA::map::delparameter($idx,'parameter_'.$which);
  &Apache::lonnet::devalidate_title_cache($renamed_url);  
     } else {   &remember_parms($idx,$which,'del');
  return 0;      }
     }      return 1;
     return 1;  }
 }  
   
 sub editor {  sub handle_edit_cmd {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;      my ($coursenum,$coursedom) =@_;
   
     my $container= ($env{'form.pagepath'}) ? 'page'      my ($cmd,$idx)=split('_',$env{'form.cmd'});
                            : 'sequence';  
       my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,      my ($title, $url, @rrest) = split(':', $ratstr);
     $folder.'.'.$container);  
     return $errtext if ($fatal);      if ($cmd eq 'del') {
    if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
     if ($#LONCAPA::map::order<1) {      ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
  my $idx=&LONCAPA::map::getresidx();      &Apache::lonnet::removeuploadedurl($url);
  if ($idx<=0) { $idx=1; }   } else {
         $LONCAPA::map::order[0]=$idx;      &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
         $LONCAPA::map::resources[$idx]='';   }
     }   splice(@LONCAPA::map::order, $idx, 1);
       
     my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=      } elsif ($cmd eq 'cut') {
  &breadcrumbs($folder,$allowed,$type);   &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
     $r->print($breadcrumbtrail);   splice(@LONCAPA::map::order, $idx, 1);
       
 # ------------------------------------------------------------ Process commands      } elsif ($cmd eq 'up'
        && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
 # ---------------- if they are for this folder and user allowed to make changes   @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
     if (($allowed) && ($env{'form.folder'} eq $folder)) {  
 # set parameters and change order      } elsif ($cmd eq 'down'
  &snapshotbefore();       && defined($LONCAPA::map::order[$idx+1])) {
    @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
  if (&update_parameter()) {  
     ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);      } elsif ($cmd eq 'rename') {
     return $errtext if ($fatal);  
  }   my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
    if ($comment=~/\S/) {
  if ($env{'form.newpos'} && $env{'form.currentpos'}) {      $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
 # change order   $comment.':'.join(':', $url, @rrest);
     my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);   }
     splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);  # Devalidate title cache
    my $renamed_url=&LONCAPA::map::qtescape($url);
     ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);   &Apache::lonnet::devalidate_title_cache($renamed_url);
     return $errtext if ($fatal);      } else {
  }   return 0;
           }
  if ($env{'form.pastemarked'}) {      return 1;
             my $paste_res =   }
                 &do_paste_from_buffer($coursenum,$coursedom,$folder);  
             if ($paste_res eq 'ok') {  sub editor {
                 ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);      my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
                 return $errtext if ($fatal);  
             } elsif ($paste_res ne '') {      my $container= ($env{'form.pagepath'}) ? 'page'
                 $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');                             : 'sequence';
             }  
  }      my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
       $folder.'.'.$container);
  $r->print($upload_output);      return $errtext if ($fatal);
   
  if (&handle_edit_cmd()) {      if ($#LONCAPA::map::order<1) {
     ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);   my $idx=&LONCAPA::map::getresidx();
     return $errtext if ($fatal);   if ($idx<=0) { $idx=1; }
  }          $LONCAPA::map::order[0]=$idx;
 # Group import/search          $LONCAPA::map::resources[$idx]='';
  if ($env{'form.importdetail'}) {      }
     my @imports;     
     foreach my $item (split(/\&/,$env{'form.importdetail'})) {      my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
  if (defined($item)) {   &breadcrumbs($folder,$allowed,$type);
     my ($name,$url,$residx)=      $r->print($breadcrumbtrail);
  map {&unescape($_)} split(/\=/,$item);     
     push(@imports, [$name, $url, $residx]);  # ------------------------------------------------------------ Process commands
  }  
     }  # ---------------- if they are for this folder and user allowed to make changes
     ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,      if (($allowed) && ($env{'form.folder'} eq $folder)) {
     $container,'londocs',@imports);  # set parameters and change order
     return $errtext if ($fatal);   &snapshotbefore();
  }  
 # Loading a complete map   if (&update_parameter()) {
  if ($env{'form.loadmap'}) {      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
     if ($env{'form.importmap'}=~/\w/) {      return $errtext if ($fatal);
  foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {   }
     my ($title,$url,$ext,$type)=split(/\:/,$res);  
     my $idx=&LONCAPA::map::getresidx($url);   if ($env{'form.newpos'} && $env{'form.currentpos'}) {
     $LONCAPA::map::resources[$idx]=$res;  # change order
     $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;      my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
  }      splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
  ($errtext,$fatal)=&storemap($coursenum,$coursedom,  
     $folder.'.'.$container);      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
  return $errtext if ($fatal);      return $errtext if ($fatal);
     } else {   }
  $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');      
    if ($env{'form.pastemarked'}) {
     }              my $paste_res =
  }                  &do_paste_from_buffer($coursenum,$coursedom,$folder);
  &log_differences($plain);              if ($paste_res eq 'ok') {
     }                  ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
 # ---------------------------------------------------------------- End commands                  return $errtext if ($fatal);
 # ---------------------------------------------------------------- Print screen              } elsif ($paste_res ne '') {
     my $idx=0;                  $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
     my $shown=0;              }
     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {   }
  $r->print('<p>'.&mt('Parameters').':<ul>'.  
   ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').   $r->print($upload_output);
   ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').  
   ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').   if (&handle_edit_cmd()) {
   '</ul></p>');      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
     }                                                                                                           return $errtext if ($fatal);
     if ($randompick>=0) {   }
  $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');  # Group import/search
     }   if ($env{'form.importdetail'}) {
     if ($is_random_order) {      my @imports;
  $r->print('<p>'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'</p>');      foreach my $item (split(/\&/,$env{'form.importdetail'})) {
     }   if (defined($item)) {
     $r->print('<table class="LC_docs_editor">');      my ($name,$url,$residx)=
     foreach my $res (@LONCAPA::map::order) {   map {&unescape($_)} split(/\=/,$item);
  my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);      push(@imports, [$name, $url, $residx]);
  $name=&LONCAPA::map::qtescape($name);   }
  $url=&LONCAPA::map::qtescape($url);      }
  unless ($name) {  $name=(split(/\//,$url))[-1]; }      ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
  unless ($name) { $idx++; next; }      $container,'londocs',@imports);
  $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,      return $errtext if ($fatal);
      $coursenum));   }
  $idx++;  # Loading a complete map
  $shown++;   if ($env{'form.loadmap'}) {
     }      if ($env{'form.importmap'}=~/\w/) {
     unless ($shown) {   foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
  $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');      my ($title,$url,$ext,$type)=split(/\:/,$res);
     }      my $idx=&LONCAPA::map::getresidx($url);
     $r->print("\n</table>\n");      $LONCAPA::map::resources[$idx]=$res;
     if ($allowed) {      $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
         &print_paste_buffer($r,$container);   }
     }   ($errtext,$fatal)=&storemap($coursenum,$coursedom,
     return;      $folder.'.'.$container);
 }   return $errtext if ($fatal);
       } else {
 sub process_file_upload {   $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;  
 # upload a file, if present      }
     my $parseaction;   }
    if ($env{'form.parserflag'}) {   &log_differences($plain);
         $parseaction = 'parse';      }
     }  # ---------------------------------------------------------------- End commands
     my $phase_status;  # ---------------------------------------------------------------- Print screen
     my $folder=$env{'form.folder'};      my $idx=0;
     if ($folder eq '') {      my $shown=0;
         $folder='default';      if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
     }   $r->print('<p>'.&mt('Parameters').':<ul>'.
     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {    ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
         my $errtext='';    ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
         my $fatal=0;    ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
         my $container='sequence';    '</ul></p>');
         if ($env{'form.pagepath'}) {      }                                                                                                    
             $container='page';      if ($randompick>=0) {
         }   $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
         ($errtext,$fatal)=      }
               &mapread($coursenum,$coursedom,$folder.'.'.$container);      if ($is_random_order) {
         if ($#LONCAPA::map::order<1) {   $r->print('<p>'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'</p>');
             $LONCAPA::map::order[0]=1;      }
             $LONCAPA::map::resources[1]='';      $r->print('<table class="LC_docs_editor">');
         }      foreach my $res (@LONCAPA::map::order) {
         if ($fatal) {   my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
             return 'failed';   $name=&LONCAPA::map::qtescape($name);
         }   $url=&LONCAPA::map::qtescape($url);
         my $destination = 'docs/';   unless ($name) {  $name=(split(/\//,$url))[-1]; }
         if ($folder =~ /^supplemental/) {   unless ($name) { $idx++; next; }
             $destination = 'supplemental/';   $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
         }       $coursenum));
         if (($folder eq 'default') || ($folder eq 'supplemental')) {   $idx++;
             $destination .= 'default/';   $shown++;
         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {      }
             $destination .=  $2.'/';      unless ($shown) {
         }   $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
 # this is for a course, not a user, so set coursedoc flag      }
 # probably the only place in the system where this should be "1"      $r->print("\n</table>\n");
         my $newidx=&LONCAPA::map::getresidx();      if ($allowed) {
         $destination .= $newidx;          &print_paste_buffer($r,$container);
         my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,      }
  $parseaction,$allfiles,      return;
  $codebase);  }
         my $ext='false';  
         if ($url=~m{^http://}) { $ext='true'; }  sub process_file_upload {
  $url     = &LONCAPA::map::qtunescape($url);      my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
         my $comment=$env{'form.comment'};  # upload a file, if present
  $comment = &LONCAPA::map::qtunescape($comment);      my $parseaction;
         if ($folder=~/^supplemental/) {     if ($env{'form.parserflag'}) {
               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.          $parseaction = 'parse';
                   $env{'user.domain'}.'___&&&___'.$comment;      }
         }      my $phase_status;
       my $folder=$env{'form.folder'};
         $LONCAPA::map::resources[$newidx]=      if ($folder eq '') {
     $comment.':'.$url.':'.$ext.':normal:res';          $folder='default';
         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;      }
         ($errtext,$fatal)=&storemap($coursenum,$coursedom,      if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
     $folder.'.'.$container);          my $errtext='';
         if ($fatal) {          my $fatal=0;
             $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';          my $container='sequence';
             return 'failed';          if ($env{'form.pagepath'}) {
         } else {              $container='page';
             if ($parseaction eq 'parse') {          }
                 my $total_embedded = keys(%{$allfiles});          ($errtext,$fatal)=
                 if ($total_embedded > 0) {                &mapread($coursenum,$coursedom,$folder.'.'.$container);
                     my $num = 0;          if ($#LONCAPA::map::order<1) {
     my $state = '              $LONCAPA::map::order[0]=1;
    <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />              $LONCAPA::map::resources[1]='';
    <input type="hidden" name="cmd" value="upload_embedded" />          }
    <input type="hidden" name="newidx" value="'.$newidx.'" />          if ($fatal) {
    <input type="hidden" name="primaryurl" value="'.&escape($url).'" />              return 'failed';
    <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';          }
     $phase_status = 'phasetwo';          my $destination = 'docs/';
           if ($folder =~ /^supplemental/) {
                     $$upload_output .=               $destination = 'supplemental/';
  'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.          }
  &Apache::loncommon::ask_for_embedded_content(          if (($folder eq 'default') || ($folder eq 'supplemental')) {
                             '/adm/coursedocs',$state,$allfiles,$codebase);              $destination .= 'default/';
                 } else {          } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                     $$upload_output .= 'No embedded items identified<br />';              $destination .=  $2.'/';
                 }          }
             }  # this is for a course, not a user, so set coursedoc flag
         }  # probably the only place in the system where this should be "1"
     }          my $newidx=&LONCAPA::map::getresidx();
     return $phase_status;          $destination .= $newidx;
 }          my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
    $parseaction,$allfiles,
 sub process_secondary_uploads {   $codebase);
     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;          my $ext='false';
     my $folder=$env{'form.folder'};          if ($url=~m{^http://}) { $ext='true'; }
     my $destination = 'docs/';   $url     = &LONCAPA::map::qtunescape($url);
     if ($folder =~ /^supplemental/) {          my $comment=$env{'form.comment'};
         $destination = 'supplemental/';   $comment = &LONCAPA::map::qtunescape($comment);
     }          if ($folder=~/^supplemental/) {
     if (($folder eq 'default') || ($folder eq 'supplemental')) {                $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
         $destination .= 'default/';                    $env{'user.domain'}.'___&&&___'.$comment;
     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {          }
         $destination .=  $2.'/';  
     }          $LONCAPA::map::resources[$newidx]=
     $destination .= $newidx;      $comment.':'.$url.':'.$ext.':normal:res';
     my ($url,$filename);          $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);          ($errtext,$fatal)=&storemap($coursenum,$coursedom,
     ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});      $folder.'.'.$container);
     return $filename;          if ($fatal) {
 }              $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
               return 'failed';
 sub is_supplemental_title {          } else {
     my ($title) = @_;              if ($parseaction eq 'parse') {
     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);                  my $total_embedded = keys(%{$allfiles});
 }                  if ($total_embedded > 0) {
                       my $num = 0;
 sub parse_supplemental_title {      my $state = '
     my ($title) = @_;     <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
      <input type="hidden" name="cmd" value="upload_embedded" />
     my ($foldertitle,$renametitle);     <input type="hidden" name="newidx" value="'.$newidx.'" />
     if ($title =~ /&amp;&amp;&amp;/) {     <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
  $title = &HTML::Entites::decode($title);     <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
     }      $phase_status = 'phasetwo';
  if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {  
  $renametitle=$4;                      $$upload_output .=
  my ($time,$uname,$udom) = ($1,$2,$3);   'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
  $foldertitle=&Apache::lontexconvert::msgtexconverted($4);   &Apache::loncommon::ask_for_embedded_content(
  my $name =  &Apache::loncommon::plainname($uname,$udom);                              '/adm/coursedocs',$state,$allfiles,$codebase);
  $name = &HTML::Entities::encode($name,'"<>&\'');                  } else {
  $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.                      $$upload_output .= 'No embedded items identified<br />';
     $name.': <br />'.$foldertitle;                  }
     }              }
     if (wantarray) {          }
  return ($title,$foldertitle,$renametitle);      }
     }       return $phase_status;
     return $title;  }
 }  
   sub process_secondary_uploads {
 # --------------------------------------------------------------- An entry line      my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
       my $folder=$env{'form.folder'};
 sub entryline {      my $destination = 'docs/';
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;      if ($folder =~ /^supplemental/) {
           $destination = 'supplemental/';
     my ($foldertitle,$pagetitle,$renametitle);      }
     if (&is_supplemental_title($title)) {      if (($folder eq 'default') || ($folder eq 'supplemental')) {
  ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);          $destination .= 'default/';
  $pagetitle = $foldertitle;      } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
     } else {          $destination .=  $2.'/';
  $title=&HTML::Entities::encode($title,'"<>&\'');      }
  $renametitle=$title;      $destination .= $newidx;
  $foldertitle=$title;      my ($url,$filename);
  $pagetitle=$title;      $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
     }      ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
       return $filename;
     my $orderidx=$LONCAPA::map::order[$index];  }
       
   sub is_supplemental_title {
     $renametitle=~s/\\/\\\\/g;      my ($title) = @_;
     $renametitle=~s/\&quot\;/\\\"/g;      return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
     $renametitle=~s/ /%20/g;  }
     my $line='<tr>';  
     my ($form_start,$form_end);  sub parse_supplemental_title {
 # Edit commands      my ($title) = @_;
     my ($container, $type, $esc_path, $path, $symb);  
     if ($env{'form.folderpath'}) {      my ($foldertitle,$renametitle);
  $type = 'folder';      if ($title =~ /&amp;&amp;&amp;/) {
         $container = 'sequence';   $title = &HTML::Entites::decode($title);
  $esc_path=&escape($env{'form.folderpath'});      }
  $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');   if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
  # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');   $renametitle=$4;
     }   my ($time,$uname,$udom) = ($1,$2,$3);
     if ($env{'form.pagepath'}) {   $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
         $type = $container = 'page';   my $name =  &Apache::loncommon::plainname($uname,$udom);
         $esc_path=&escape($path = $env{'form.pagepath'});   $name = &HTML::Entities::encode($name,'"<>&\'');
  $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');   $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
         $symb=&escape($env{'form.pagesymb'});      $name.': <br />'.$foldertitle;
     }      }
     my $cpinfo='';      if (wantarray) {
     if ($allowed) {   return ($title,$foldertitle,$renametitle);
  my $incindex=$index+1;      }
  my $selectbox='';      return $title;
  if (($folder!~/^supplemental/) &&  }
     ($#LONCAPA::map::order>0) &&   
     ((split(/\:/,  # --------------------------------------------------------------- An entry line
      $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]   
      ne '') &&   sub entryline {
     ((split(/\:/,      my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
      $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]   
      ne '')) {      my ($foldertitle,$pagetitle,$renametitle);
     $selectbox=      if (&is_supplemental_title($title)) {
  '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.   ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
  '<select name="newpos" onChange="this.form.submit()">';   $pagetitle = $foldertitle;
     for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {      } else {
  if ($i==$incindex) {   $title=&HTML::Entities::encode($title,'"<>&\'');
     $selectbox.='<option value="" selected="1">('.$i.')</option>';   $renametitle=$title;
  } else {   $foldertitle=$title;
     $selectbox.='<option value="'.$i.'">'.$i.'</option>';   $pagetitle=$title;
  }      }
     }  
     $selectbox.='</select>';      my $orderidx=$LONCAPA::map::order[$index];
  }     
  my %lt=&Apache::lonlocal::texthash(  
                 'up' => 'Move Up',      $renametitle=~s/\\/\\\\/g;
  'dw' => 'Move Down',      $renametitle=~s/\&quot\;/\\\"/g;
  'rm' => 'Remove',      $renametitle=~s/ /%20/g;
                 'ct' => 'Cut',      my $line='<tr>';
  'rn' => 'Rename',      my ($form_start,$form_end);
  'cp' => 'Copy');  # Edit commands
  my $nocopy=0;      my ($container, $type, $esc_path, $path, $symb);
         my $nocut=0;      if ($env{'form.folderpath'}) {
         if ($url=~/\.(page|sequence)$/) {   $type = 'folder';
     if ($url =~ m{/res/}) {          $container = 'sequence';
  # no copy for published maps   $esc_path=&escape($env{'form.folderpath'});
  $nocopy = 1;   $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
     } else {   # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
  foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {      }
     my ($title,$url,$ext,$type)=split(/\:/,$item);      if ($env{'form.pagepath'}) {
     if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {          $type = $container = 'page';
  $nocopy=1;          $esc_path=&escape($path = $env{'form.pagepath'});
  last;   $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
     }          $symb=&escape($env{'form.pagesymb'});
  }      }
     }      my $cpinfo='';
  }      if ($allowed) {
         if ($url=~/^\/res\/lib\/templates\//) {    my $incindex=$index+1;
            $nocopy=1;    my $selectbox='';
            $nocut=1;   if (($folder!~/^supplemental/) &&
         }      ($#LONCAPA::map::order>0) &&
         my $copylink='&nbsp;';      ((split(/\:/,
         my $cutlink='&nbsp;';       $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
        ne '') &&
  my $skip_confirm = 0;      ((split(/\:/,
  if ( $folder =~ /^supplemental/       $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
      || ($url =~ m{( /smppg$       ne '')) {
     |/syllabus$      $selectbox=
     |/aboutme$   '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
     |/navmaps$   '<select name="newpos" onChange="this.form.submit()">';
     |/bulletinboard$      for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
     |\.html$   if ($i==$incindex) {
     |^/adm/wrapper/ext)}x)) {      $selectbox.='<option value="" selected="1">('.$i.')</option>';
     $skip_confirm = 1;   } else {
  }      $selectbox.='<option value="'.$i.'">'.$i.'</option>';
    }
  if (!$nocopy) {      }
     $copylink=(<<ENDCOPY);      $selectbox.='</select>';
 <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>   }
 ENDCOPY   my %lt=&Apache::lonlocal::texthash(
         }                  'up' => 'Move Up',
  if (!$nocut) {   'dw' => 'Move Down',
     $cutlink=(<<ENDCUT);   'rm' => 'Remove',
 <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>                  'ct' => 'Cut',
 ENDCUT   'rn' => 'Rename',
         }   'cp' => 'Copy');
  $form_start = (<<END);   my $nocopy=0;
    <form  action="/adm/coursedocs" method="post">          my $nocut=0;
    <input type="hidden" name="${type}path" value="$path" />          if ($url=~/\.(page|sequence)$/) {
    <input type="hidden" name="${type}symb" value="$symb" />      if ($url =~ m{/res/}) {
    <input type="hidden" name="setparms" value="$orderidx" />   # no copy for published maps
    <input type="hidden" name="changeparms" value="0" />   $nocopy = 1;
 END      } else {
         $form_end = '</form>';   foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
  $line.=(<<END);      my ($title,$url,$ext,$type)=split(/\:/,$item);
 <td>      if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
    <table class="LC_docs_entry_move">   $nocopy=1;
       <tr>   last;
          <td>      }
             <a href='/adm/coursedocs?cmd=up_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'><img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" /></a>   }
          </td>      }
       </tr>   }
       <tr>          if ($url=~/^\/res\/lib\/templates\//) {
         <td>             $nocopy=1;
            <a href='/adm/coursedocs?cmd=down_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'><img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" /></a>             $nocut=1;
         </td>          }
       </tr>          my $copylink='&nbsp;';
     </table>          my $cutlink='&nbsp;';
 </td>  
 <td>   my $skip_confirm = 0;
    $form_start   if ( $folder =~ /^supplemental/
    $selectbox       || ($url =~ m{( /smppg$
    $form_end      |/syllabus$
 </td>      |/aboutme$
 <td class="LC_docs_entry_commands">      |/navmaps$
    <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>      |/bulletinboard$
 $cutlink      |\.html$
    <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>      |^/adm/wrapper/ext)}x)) {
 $copylink      $skip_confirm = 1;
 </td>   }
 END  
    if (!$nocopy) {
     }      $copylink=(<<ENDCOPY);
 # Figure out what kind of a resource this is  <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
     my ($extension)=($url=~/\.(\w+)$/);  ENDCOPY
     my $uploaded=($url=~/^\/*uploaded\//);          }
     my $icon=&Apache::loncommon::icon($url);   if (!$nocut) {
     my $isfolder=0;      $cutlink=(<<ENDCUT);
     my $ispage=0;  <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
     my $folderarg;  ENDCUT
     my $pagearg;          }
     my $pagefile;   $form_start = (<<END);
     if ($uploaded) {     <form  action="/adm/coursedocs" method="post">
  if ($extension eq 'sequence') {     <input type="hidden" name="${type}path" value="$path" />
     $icon=$iconpath.'/folder_closed.gif';     <input type="hidden" name="${type}symb" value="$symb" />
     $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;     <input type="hidden" name="setparms" value="$orderidx" />
     $url='/adm/coursedocs?';     <input type="hidden" name="changeparms" value="0" />
     $folderarg=$1;  END
     $isfolder=1;          $form_end = '</form>';
         } elsif ($extension eq 'page') {   $line.=(<<END);
             $icon=$iconpath.'/page.gif';  <td>
             $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;     <table class="LC_docs_entry_move">
             $pagearg=$1;        <tr>
             $url='/adm/coursedocs?';           <td>
             $ispage=1;              <a href='/adm/coursedocs?cmd=up_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'><img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" /></a>
  } else {           </td>
     &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);        </tr>
  }        <tr>
     }          <td>
                  <a href='/adm/coursedocs?cmd=down_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'><img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" /></a>
     my $orig_url = $url;          </td>
     my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});        </tr>
     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {      </table>
  my $symb=&Apache::lonnet::symbclean(  </td>
           &Apache::lonnet::declutter('uploaded/'.  <td>
            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.     $form_start
            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.     $selectbox
            '.sequence').     $form_end
            '___'.$residx.'___'.  </td>
    &Apache::lonnet::declutter($url));  <td class="LC_docs_entry_commands">
  (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);     <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
  $url=&Apache::lonnet::clutter($url);  $cutlink
  if ($url=~/^\/*uploaded\//) {     <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
     $url=~/\.(\w+)$/;  $copylink
     my $embstyle=&Apache::loncommon::fileembstyle($1);  </td>
     if (($embstyle eq 'img') || ($embstyle eq 'emb')) {  END
  $url='/adm/wrapper'.$url;  
     } elsif ($embstyle eq 'ssi') {      }
  #do nothing with these  # Figure out what kind of a resource this is
     } elsif ($url!~/\.(sequence|page)$/) {      my ($extension)=($url=~/\.(\w+)$/);
  $url='/adm/coursedocs/showdoc'.$url;      my $uploaded=($url=~/^\/*uploaded\//);
     }      my $icon=&Apache::loncommon::icon($url);
  } elsif ($url=~m|^/ext/|) {       my $isfolder=0;
     $url='/adm/wrapper'.$url;      my $ispage=0;
     $external = 1;      my $folderarg;
  }      my $pagearg;
         if (&Apache::lonnet::symbverify($symb,$url)) {      my $pagefile;
     $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);      if ($uploaded) {
         } else {   if ($extension eq 'sequence') {
             $url='';      $icon=$iconpath.'/folder_closed.gif';
         }      $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
  if ($container eq 'page') {      $url='/adm/coursedocs?';
     my $symb=$env{'form.pagesymb'};      $folderarg=$1;
               $isfolder=1;
     $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);          } elsif ($extension eq 'page') {
     $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);              $icon=$iconpath.'/page.gif';
  }              $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
     }              $pagearg=$1;
     my ($parameterset,$rand_order_text) = ('&nbsp;', '&nbsp;');              $url='/adm/coursedocs?';
     if ($isfolder || $extension eq 'sequence') {              $ispage=1;
  my $foldername=&escape($foldertitle);   } else {
  my $folderpath=$env{'form.folderpath'};      &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
  if ($folderpath) { $folderpath.='&' };   }
 # Append randompick number, hidden, and encrypted with ":" to foldername,       }
 # so it gets transferred between levels     
  $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,      my $orig_url = $url;
                                               'parameter_randompick'))[0]      my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
                                                .':'.((&LONCAPA::map::getparameter($orderidx,      if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
                                               'parameter_hiddenresource'))[0]=~/^yes$/i)   my $symb=&Apache::lonnet::symbclean(
                                                .':'.((&LONCAPA::map::getparameter($orderidx,            &Apache::lonnet::declutter('uploaded/'.
                                               'parameter_encrypturl'))[0]=~/^yes$/i)             $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                                                .':'.((&LONCAPA::map::getparameter($orderidx,             $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
                                               'parameter_randomorder'))[0]=~/^yes$/i);             '.sequence').
  $url.='folderpath='.&escape($folderpath).$cpinfo;             '___'.$residx.'___'.
  $parameterset='<label>'.&mt('Randomly Pick: ').     &Apache::lonnet::declutter($url));
     '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.   (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
     (&LONCAPA::map::getparameter($orderidx,   $url=&Apache::lonnet::clutter($url);
                                               'parameter_randompick'))[0].   if ($url=~/^\/*uploaded\//) {
                                               '" />'.      $url=~/\.(\w+)$/;
 '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';      my $embstyle=&Apache::loncommon::fileembstyle($1);
     my $ro_set=      if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
     ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');   $url='/adm/wrapper'.$url;
  $rand_order_text ='      } elsif ($embstyle eq 'ssi') {
 <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';      #do nothing with these
     }      } elsif ($url!~/\.(sequence|page)$/) {
     if ($ispage) {   $url='/adm/coursedocs/showdoc'.$url;
         my $pagename=&escape($pagetitle);      }
         my $pagepath;   } elsif ($url=~m|^/ext/|) {
         my $folderpath=$env{'form.folderpath'};      $url='/adm/wrapper'.$url;
         if ($folderpath) { $pagepath = $folderpath.'&' };      $external = 1;
         $pagepath.=$pagearg.'&'.$pagename;   }
  my $symb=$env{'form.pagesymb'};          if (&Apache::lonnet::symbverify($symb,$url)) {
  if (!$symb) {      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
     my $path='uploaded/'.          } else {
  $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.              $url='';
  $env{'course.'.$env{'request.course.id'}.'.num'}.'/';          }
     $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',   if ($container eq 'page') {
        $residx,      my $symb=$env{'form.pagesymb'};
        $path.$pagearg.'.page');          
  }      $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
  $url.='pagepath='.&escape($pagepath).      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
     '&amp;pagesymb='.&escape($symb).$cpinfo;   }
     }      }
     if ($external) {      my ($parameterset,$rand_order_text) = ('&nbsp;', '&nbsp;');
  my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';      if ($isfolder || $extension eq 'sequence') {
  $external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';   my $foldername=&escape($foldertitle);
     } else {   my $folderpath=$env{'form.folderpath'};
  undef($external);   if ($folderpath) { $folderpath.='&' };
     }  # Append randompick number, hidden, and encrypted with ":" to foldername,
     $line.='  # so it gets transferred between levels
   <td class="LC_docs_entry_icon">   $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
     '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'                                                'parameter_randompick'))[0]
   </td>                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
   <td class="LC_docs_entry_title">                                                'parameter_hiddenresource'))[0]=~/^yes$/i)
     '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
   </td>";                                                'parameter_encrypturl'))[0]=~/^yes$/i)
     if (($allowed) && ($folder!~/^supplemental/)) {                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
   my %lt=&Apache::lonlocal::texthash(                                                'parameter_randomorder'))[0]=~/^yes$/i);
        'hd' => 'Hidden',   $url.='folderpath='.&escape($folderpath).$cpinfo;
        'ec' => 'URL hidden');   $parameterset='<label>'.&mt('Randomly Pick: ').
  my $enctext=      '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
     ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');      (&LONCAPA::map::getparameter($orderidx,
  my $hidtext=                                                'parameter_randompick'))[0].
     ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');                                                '" />'.
  $line.=(<<ENDPARMS);  '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
   <td class="LC_docs_entry_parameter">      my $ro_set=
     $form_start      ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
     <label><input type="checkbox" name="hiddenresource_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>   $rand_order_text ='
     $form_end  <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';  
   </td>      }
   <td class="LC_docs_entry_parameter">      if ($ispage) {
     $form_start          my $pagename=&escape($pagetitle);
     <label><input type="checkbox" name="encrypturl_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>          my $pagepath;
     $form_end          my $folderpath=$env{'form.folderpath'};
   </td>          if ($folderpath) { $pagepath = $folderpath.'&' };
   <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>          $pagepath.=$pagearg.'&'.$pagename;
   <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>   my $symb=$env{'form.pagesymb'};
 ENDPARMS   if (!$symb) {
     }      my $path='uploaded/'.
     $line.="</tr>";   $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
     return $line;   $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
 }      $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
          $residx,
 =pod         $path.$pagearg.'.page');
    }
 =item tiehash()   $url.='pagepath='.&escape($pagepath).
       '&amp;pagesymb='.&escape($symb).$cpinfo;
 tie the hash      }
       if ($external) {
 =cut   my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
    $external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
 sub tiehash {      } else {
     my ($mode)=@_;   undef($external);
     $hashtied=0;      }
     if ($env{'request.course.fn'}) {      $line.='
  if ($mode eq 'write') {    <td class="LC_docs_entry_icon">
     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",      '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
     &GDBM_WRCREAT(),0640)) {    </td>
                 $hashtied=2;    <td class="LC_docs_entry_title">
     }      '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
  } else {    </td>";
     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",      if (($allowed) && ($folder!~/^supplemental/)) {
     &GDBM_READER(),0640)) {    my %lt=&Apache::lonlocal::texthash(
                 $hashtied=1;         'hd' => 'Hidden',
     }         'ec' => 'URL hidden');
  }   my $enctext=
     }          ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
 }   my $hidtext=
       ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
 sub untiehash {   $line.=(<<ENDPARMS);
     if ($hashtied) { untie %hash; }    <td class="LC_docs_entry_parameter">
     $hashtied=0;      $form_start
     return OK;      <label><input type="checkbox" name="hiddenresource_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
 }      $form_end
     </td>
     <td class="LC_docs_entry_parameter">
       $form_start
       <label><input type="checkbox" name="encrypturl_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
 sub checkonthis {      $form_end
     my ($r,$url,$level,$title)=@_;    </td>
     $url=&unescape($url);    <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
     $alreadyseen{$url}=1;    <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
     $r->rflush();  ENDPARMS
     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {      }
        $r->print("\n<br />");      $line.="</tr>";
        if ($level==0) {      return $line;
            $r->print("<br />");  }
        }  
        for (my $i=0;$i<=$level*5;$i++) {  =pod
            $r->print('&nbsp;');  
        }  =item tiehash()
        $r->print('<a href="'.$url.'" target="cat">'.  
  ($title?$title:$url).'</a> ');  tie the hash
        if ($url=~/^\/res\//) {  
   my $result=&Apache::lonnet::repcopy(  =cut
                               &Apache::lonnet::filelocation('',$url));  
           if ($result eq 'ok') {  sub tiehash {
              $r->print('<span class="LC_success">'.&mt('ok').'</span>');      my ($mode)=@_;
              $r->rflush();      $hashtied=0;
              &Apache::lonnet::countacc($url);      if ($env{'request.course.fn'}) {
              $url=~/\.(\w+)$/;   if ($mode eq 'write') {
              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {      if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
  $r->print('<br />');      &GDBM_WRCREAT(),0640)) {
                  $r->rflush();                  $hashtied=2;
                  for (my $i=0;$i<=$level*5;$i++) {      }
                      $r->print('&nbsp;');   } else {
                  }      if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                  $r->print('- '.&mt('Rendering:').' ');      &GDBM_READER(),0640)) {
  my ($errorcount,$warningcount)=split(/:/,                  $hashtied=1;
        &Apache::lonnet::ssi_body($url,      }
        ('grade_target'=>'web',   }
  'return_only_error_and_warning_counts' => 1)));      }    
                  if (($errorcount) ||  }
                      ($warningcount)) {  
      if ($errorcount) {  sub untiehash {
                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.      if ($hashtied) { untie %hash; }
                           &mt('[quant,_1,error]',$errorcount).'</span>');      $hashtied=0;
                      }      return OK;
      if ($warningcount) {  }
                         $r->print('<span class="LC_warning">'.  
                           &mt('[quant,_1,warning]',$warningcount).'</span>');  
                      }  
                  } else {  
                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');  sub checkonthis {
                  }      my ($r,$url,$level,$title)=@_;
                  $r->rflush();      $url=&unescape($url);
              }      $alreadyseen{$url}=1;
      my $dependencies=      $r->rflush();
                 &Apache::lonnet::metadata($url,'dependencies');      if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
              foreach my $dep (split(/\,/,$dependencies)) {         $r->print("\n<br />");
  if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {         if ($level==0) {
                     &checkonthis($r,$dep,$level+1);             $r->print("<br />");
                  }         }
              }         for (my $i=0;$i<=$level*5;$i++) {
           } elsif ($result eq 'unavailable') {             $r->print('&nbsp;');
              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');         }
           } elsif ($result eq 'not_found') {         $r->print('<a href="'.$url.'" target="cat">'.
       unless ($url=~/\$/) {   ($title?$title:$url).'</a> ');
   $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');         if ($url=~/^\/res\//) {
       } else {    my $result=&Apache::lonnet::repcopy(
   $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');                                &Apache::lonnet::filelocation('',$url));
       }            if ($result eq 'ok') {
           } else {               $r->print('<span class="LC_success">'.&mt('ok').'</span>');
              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');               $r->rflush();
           }               &Apache::lonnet::countacc($url);
        }               $url=~/\.(\w+)$/;
     }               if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
 }   $r->print('<br />');
                    $r->rflush();
                    for (my $i=0;$i<=$level*5;$i++) {
                        $r->print('&nbsp;');
 =pod                   }
                    $r->print('- '.&mt('Rendering:').' ');
 =item list_symbs()   my ($errorcount,$warningcount)=split(/:/,
          &Apache::lonnet::ssi_body($url,
 List Symbs         ('grade_target'=>'web',
    'return_only_error_and_warning_counts' => 1)));
 =cut                   if (($errorcount) ||
                        ($warningcount)) {
 sub list_symbs {       if ($errorcount) {
     my ($r) = @_;                          $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
                             &mt('[quant,_1,error]',$errorcount).'</span>');
     $r->print(&Apache::loncommon::start_page('Symb List'));                       }
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));       if ($warningcount) {
     my $navmap = Apache::lonnavmaps::navmap->new();                          $r->print('<span class="LC_warning">'.
     $r->print("<pre>\n");                            &mt('[quant,_1,warning]',$warningcount).'</span>');
     foreach my $res ($navmap->retrieveResources()) {                       }
  $r->print($res->compTitle()."\t".$res->symb()."\n");                   } else {
     }                       $r->print('<span class="LC_success">'.&mt('ok').'</span>');
     $r->print("\n</pre>\n");                   }
     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');                   $r->rflush();
 }               }
        my $dependencies=
                   &Apache::lonnet::metadata($url,'dependencies');
                foreach my $dep (split(/\,/,$dependencies)) {
 sub verifycontent {   if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
     my ($r) = @_;                      &checkonthis($r,$dep,$level+1);
     my $type = &Apache::loncommon::course_type();                   }
    my $loaderror=&Apache::lonnet::overloaderror($r);               }
    if ($loaderror) { return $loaderror; }            } elsif ($result eq 'unavailable') {
    $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));               $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));            } elsif ($result eq 'not_found') {
    $hashtied=0;        unless ($url=~/\$/) {
    undef %alreadyseen;    $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
    %alreadyseen=();        } else {
    &tiehash();    $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
    foreach my $key (keys(%hash)) {        }
        if ($hash{$key}=~/\.(page|sequence)$/) {            } else {
    if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {               $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
        $r->print('<hr /><span class="LC_error">'.            }
  &mt('The following sequence or page is included more than once in your '.$type.': ').         }
  &unescape($hash{$key}).'</span><br />'.      }
  &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));  }
    }  
        }  
        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {  
            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});  =pod
        }  
    }  =item list_symbs()
    &untiehash();  
    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.  List Symbs
      &mt('Return to DOCS').'</a>');  
 }  =cut
   
   sub list_symbs {
 sub devalidateversioncache {      my ($r) = @_;
     my $src=shift;  
     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.      my $type = &Apache::loncommon::course_type();
   &Apache::lonnet::clutter($src));      $r->print(&Apache::loncommon::start_page('Symb List'));
 }      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
       my $navmap = Apache::lonnavmaps::navmap->new();
 sub checkversions {      if (!defined($navmap)) {
     my ($r) = @_;          $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
     my $type = &Apache::loncommon::course_type();                    '<div class="LC_error">'.
     $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));                    &mt('Unable to retrieve information about course contents').
     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));                    '</div>');
     my $header='';          &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
     my $startsel='';      } else {
     my $monthsel='';          $r->print("<pre>\n");
     my $weeksel='';          foreach my $res ($navmap->retrieveResources()) {
     my $daysel='';      $r->print($res->compTitle()."\t".$res->symb()."\n");
     my $allsel='';          }
     my %changes=();          $r->print("\n</pre>\n");
     my $starttime=0;      }
     my $haschanged=0;      $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
     my %setversions=&Apache::lonnet::dump('resourceversions',  }
   $env{'course.'.$env{'request.course.id'}.'.domain'},  
   $env{'course.'.$env{'request.course.id'}.'.num'});  
   sub verifycontent {
     $hashtied=0;      my ($r) = @_;
     &tiehash();      my $type = &Apache::loncommon::course_type();
     my %newsetversions=();     my $loaderror=&Apache::lonnet::overloaderror($r);
     if ($env{'form.setmostrecent'}) {     if ($loaderror) { return $loaderror; }
  $haschanged=1;     $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
  foreach my $key (keys(%hash)) {     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
     if ($key=~/^ids\_(\/res\/.+)$/) {     $hashtied=0;
  $newsetversions{$1}='mostrecent';     undef %alreadyseen;
                 &devalidateversioncache($1);     %alreadyseen=();
     }     &tiehash();
  }     foreach my $key (keys(%hash)) {
     } elsif ($env{'form.setcurrent'}) {         if ($hash{$key}=~/\.(page|sequence)$/) {
  $haschanged=1;     if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
  foreach my $key (keys(%hash)) {         $r->print('<hr /><span class="LC_error">'.
     if ($key=~/^ids\_(\/res\/.+)$/) {   &mt('The following sequence or page is included more than once in your '.$type.': ').
  my $getvers=&Apache::lonnet::getversion($1);   &unescape($hash{$key}).'</span><br />'.
  if ($getvers>0) {   &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
     $newsetversions{$1}=$getvers;     }
     &devalidateversioncache($1);         }
  }         if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
     }             &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
  }         }
     } elsif ($env{'form.setversions'}) {     }
  $haschanged=1;     &untiehash();
  foreach my $key (keys(%env)) {     $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
     if ($key=~/^form\.set_version_(.+)$/) {       &mt('Return to DOCS').'</a>');
  my $src=$1;  }
  if (($env{$key}) && ($env{$key} ne $setversions{$src})) {  
     $newsetversions{$src}=$env{$key};  
     &devalidateversioncache($src);  sub devalidateversioncache {
  }      my $src=shift;
     }      &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
  }    &Apache::lonnet::clutter($src));
     }  }
     if ($haschanged) {  
         if (&Apache::lonnet::put('resourceversions',\%newsetversions,  sub checkversions {
   $env{'course.'.$env{'request.course.id'}.'.domain'},      my ($r) = @_;
   $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {      my $type = &Apache::loncommon::course_type();
     $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');      $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
  } else {      $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
     $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');      my $header='';
  }      my $startsel='';
  &mark_hash_old();      my $monthsel='';
     }      my $weeksel='';
     &changewarning($r,'');      my $daysel='';
     if ($env{'form.timerange'} eq 'all') {      my $allsel='';
 # show all documents      my %changes=();
  $header=&mt('All Documents in '.$type);      my $starttime=0;
  $allsel=1;      my $haschanged=0;
  foreach my $key (keys(%hash)) {      my %setversions=&Apache::lonnet::dump('resourceversions',
     if ($key=~/^ids\_(\/res\/.+)$/) {    $env{'course.'.$env{'request.course.id'}.'.domain'},
  my $src=$1;    $env{'course.'.$env{'request.course.id'}.'.num'});
  $changes{$src}=1;  
     }      $hashtied=0;
  }      &tiehash();
     } else {      my %newsetversions=();
 # show documents which changed      if ($env{'form.setmostrecent'}) {
  %changes=&Apache::lonnet::dump   $haschanged=1;
  ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},   foreach my $key (keys(%hash)) {
                      $env{'course.'.$env{'request.course.id'}.'.num'});      if ($key=~/^ids\_(\/res\/.+)$/) {
  my $firstkey=(keys(%changes))[0];   $newsetversions{$1}='mostrecent';
  unless ($firstkey=~/^error\:/) {                  &devalidateversioncache($1);
     unless ($env{'form.timerange'}) {      }
  $env{'form.timerange'}=604800;   }
     }      } elsif ($env{'form.setcurrent'}) {
     my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '   $haschanged=1;
  .&mt('seconds');   foreach my $key (keys(%hash)) {
     if ($env{'form.timerange'}==-1) {      if ($key=~/^ids\_(\/res\/.+)$/) {
  $seltext='since start of course';   my $getvers=&Apache::lonnet::getversion($1);
  $startsel='selected';   if ($getvers>0) {
  $env{'form.timerange'}=time;      $newsetversions{$1}=$getvers;
     }      &devalidateversioncache($1);
     $starttime=time-$env{'form.timerange'};   }
     if ($env{'form.timerange'}==2592000) {      }
  $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';   }
  $monthsel='selected';      } elsif ($env{'form.setversions'}) {
     } elsif ($env{'form.timerange'}==604800) {   $haschanged=1;
  $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';   foreach my $key (keys(%env)) {
  $weeksel='selected';      if ($key=~/^form\.set_version_(.+)$/) {
     } elsif ($env{'form.timerange'}==86400) {   my $src=$1;
  $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';   if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
  $daysel='selected';      $newsetversions{$src}=$env{$key};
     }      &devalidateversioncache($src);
     $header=&mt('Content changed').' '.$seltext;   }
  } else {      }
     $header=&mt('No content modifications yet.');   }
  }      }
     }      if ($haschanged) {
     %setversions=&Apache::lonnet::dump('resourceversions',          if (&Apache::lonnet::put('resourceversions',\%newsetversions,
   $env{'course.'.$env{'request.course.id'}.'.domain'},    $env{'course.'.$env{'request.course.id'}.'.domain'},
   $env{'course.'.$env{'request.course.id'}.'.num'});    $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
     my %lt=&Apache::lonlocal::texthash      $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
       ('st' => 'Version changes since start of '.$type,   } else {
        'lm' => 'Version changes since last Month',      $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
        'lw' => 'Version changes since last Week',   }
        'sy' => 'Version changes since Yesterday',   &mark_hash_old();
                'al' => 'All Resources (possibly large output)',      }
        'sd' => 'Display',      &changewarning($r,'');
        'fi' => 'File',      if ($env{'form.timerange'} eq 'all') {
        'md' => 'Modification Date',  # show all documents
                'mr' => 'Most recently published Version',   $header=&mt('All Documents in '.$type);
        've' => 'Version used in '.$type,   $allsel=1;
                'vu' => 'Set Version to be used in '.$type,   foreach my $key (keys(%hash)) {
 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',      if ($key=~/^ids\_(\/res\/.+)$/) {
 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',   my $src=$1;
 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',   $changes{$src}=1;
        'di' => 'Differences');      }
     $r->print(<<ENDHEADERS);   }
 <form action="/adm/coursedocs" method="post">      } else {
 <input type="hidden" name="versions" value="1" />  # show documents which changed
 <input type="submit" name="setmostrecent" value="$lt{'sm'}" />   %changes=&Apache::lonnet::dump
 <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />   ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
 <select name="timerange">                       $env{'course.'.$env{'request.course.id'}.'.num'});
 <option value='all' $allsel>$lt{'al'}</option>   my $firstkey=(keys(%changes))[0];
 <option value="-1" $startsel>$lt{'st'}</option>   unless ($firstkey=~/^error\:/) {
 <option value="2592000" $monthsel>$lt{'lm'}</option>      unless ($env{'form.timerange'}) {
 <option value="604800" $weeksel>$lt{'lw'}</option>   $env{'form.timerange'}=604800;
 <option value="86400" $daysel>$lt{'sy'}</option>      }
 </select>      my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
 <input type="submit" name="display" value="$lt{'sd'}" />   .&mt('seconds');
 <h3>$header</h3>      if ($env{'form.timerange'}==-1) {
 <input type="submit" name="setversions" value="$lt{'sv'}" />   $seltext='since start of course';
 <table border="0">   $startsel='selected';
 ENDHEADERS   $env{'form.timerange'}=time;
     foreach my $key (sort(keys(%changes))) {      }
  if ($changes{$key}>$starttime) {      $starttime=time-$env{'form.timerange'};
     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);      if ($env{'form.timerange'}==2592000) {
     my $currentversion=&Apache::lonnet::getversion($key);   $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
     if ($currentversion<0) {   $monthsel='selected';
  $currentversion=&mt('Could not be determined.');      } elsif ($env{'form.timerange'}==604800) {
     }   $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
     my $linkurl=&Apache::lonnet::clutter($key);   $weeksel='selected';
     $r->print(      } elsif ($env{'form.timerange'}==86400) {
       '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.   $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
       &Apache::lonnet::gettitle($linkurl).   $daysel='selected';
                       '</b></font></td></tr>'.      }
                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.      $header=&mt('Content changed').' '.$seltext;
                       '<td colspan="4">'.   } else {
                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.      $header=&mt('No content modifications yet.');
       '</a></td></tr>'.   }
                       '<tr><td></td>'.      }
                       '<td title="'.$lt{'md'}.'">'.      %setversions=&Apache::lonnet::dump('resourceversions',
       &Apache::lonlocal::locallocaltime(    $env{'course.'.$env{'request.course.id'}.'.domain'},
                            &Apache::lonnet::metadata($root.'.'.$extension,    $env{'course.'.$env{'request.course.id'}.'.num'});
                                                      'lastrevisiondate')      my %lt=&Apache::lonlocal::texthash
                                                         ).        ('st' => 'Version changes since start of '.$type,
                       '</td>'.         'lm' => 'Version changes since last Month',
                       '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.         'lw' => 'Version changes since last Week',
                       '<font size="+1">'.$currentversion.'</font>'.         'sy' => 'Version changes since Yesterday',
                       '</span></td>'.                 'al' => 'All Resources (possibly large output)',
                       '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.         'sd' => 'Display',
                       '<font size="+1">');         'fi' => 'File',
 # Used in course         'md' => 'Modification Date',
     my $usedversion=$hash{'version_'.$linkurl};                 'mr' => 'Most recently published Version',
     if (($usedversion) && ($usedversion ne 'mostrecent')) {         've' => 'Version used in '.$type,
  $r->print($usedversion);                 'vu' => 'Set Version to be used in '.$type,
     } else {  'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
  $r->print($currentversion);  'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
     }  'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
     $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.         'di' => 'Differences');
                       '<span class="LC_nobreak">Use: ');      $r->print(<<ENDHEADERS);
 # Set version  <form action="/adm/coursedocs" method="post">
     $r->print(&Apache::loncommon::select_form($setversions{$linkurl},  <input type="hidden" name="versions" value="1" />
       'set_version_'.$linkurl,  <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
       ('select_form_order' =>  <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
        ['',1..$currentversion,'mostrecent'],  <select name="timerange">
        '' => '',  <option value='all' $allsel>$lt{'al'}</option>
        'mostrecent' => 'most recent',  <option value="-1" $startsel>$lt{'st'}</option>
        map {$_,$_} (1..$currentversion))));  <option value="2592000" $monthsel>$lt{'lm'}</option>
     $r->print('</span></td></tr><tr><td></td>');  <option value="604800" $weeksel>$lt{'lw'}</option>
     my $lastold=1;  <option value="86400" $daysel>$lt{'sy'}</option>
     for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {  </select>
  my $url=$root.'.'.$prevvers.'.'.$extension;  <input type="submit" name="display" value="$lt{'sd'}" />
  if (&Apache::lonnet::metadata($url,'lastrevisiondate')<  <h3>$header</h3>
     $starttime) {  <input type="submit" name="setversions" value="$lt{'sv'}" />
     $lastold=$prevvers;  <table border="0">
  }  ENDHEADERS
     }      foreach my $key (sort(keys(%changes))) {
             #    if ($changes{$key}>$starttime) {
             # Code to figure out how many version entries should go in      my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
             # each of the four columns      my $currentversion=&Apache::lonnet::getversion($key);
             my $entries_per_col = 0;      if ($currentversion<0) {
             my $num_entries = ($currentversion-$lastold);   $currentversion=&mt('Could not be determined.');
             if ($num_entries % 4 == 0) {      }
                 $entries_per_col = $num_entries/4;      my $linkurl=&Apache::lonnet::clutter($key);
             } else {      $r->print(
                 $entries_per_col = $num_entries/4 + 1;        '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
             }        &Apache::lonnet::gettitle($linkurl).
             my $entries_count = 0;                        '</b></font></td></tr>'.
             $r->print('<td valign="top"><font size="-2">');                         '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
             my $cols_output = 1;                        '<td colspan="4">'.
             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {                        '<a href="'.$linkurl.'" target="cat">'.$linkurl.
  my $url=$root.'.'.$prevvers.'.'.$extension;        '</a></td></tr>'.
  $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).                        '<tr><td></td>'.
   '">'.&mt('Version').' '.$prevvers.'</a> ('.                        '<td title="'.$lt{'md'}.'">'.
   &Apache::lonlocal::locallocaltime(        &Apache::lonlocal::locallocaltime(
                                 &Apache::lonnet::metadata($url,                             &Apache::lonnet::metadata($root.'.'.$extension,
                                                           'lastrevisiondate')                                                       'lastrevisiondate')
                                                             ).                                                          ).
   ')');                        '</td>'.
  if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {                        '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
                     $r->print(' <a href="/adm/diff?filename='.                        '<font size="+1">'.$currentversion.'</font>'.
       &Apache::lonnet::clutter($root.'.'.$extension).                        '</span></td>'.
       '&versionone='.$prevvers.                        '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
       '">'.&mt('Diffs').'</a>');                        '<font size="+1">');
  }  # Used in course
  $r->print('</span><br />');      my $usedversion=$hash{'version_'.$linkurl};
                 if (++$entries_count % $entries_per_col == 0) {      if (($usedversion) && ($usedversion ne 'mostrecent')) {
                     $r->print('</font></td>');   $r->print($usedversion);
                     if ($cols_output != 4) {      } else {
                         $r->print('<td valign="top"><font size="-2">');   $r->print($currentversion);
                         $cols_output++;      }
                     }      $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
                 }                        '<span class="LC_nobreak">Use: ');
     }  # Set version
             while($cols_output++ < 4) {      $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
                 $r->print('</font></td><td><font>')        'set_version_'.$linkurl,
             }        ('select_form_order' =>
     $r->print('</font></td></tr>'."\n");         ['',1..$currentversion,'mostrecent'],
  }         '' => '',
     }         'mostrecent' => 'most recent',
     $r->print('</table></form>');         map {$_,$_} (1..$currentversion))));
     $r->print('<h1>'.&mt('Done').'.</h1>');      $r->print('</span></td></tr><tr><td></td>');
       my $lastold=1;
     &untiehash();      for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
 }   my $url=$root.'.'.$prevvers.'.'.$extension;
    if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
 sub mark_hash_old {      $starttime) {
     my $retie_hash=0;      $lastold=$prevvers;
     if ($hashtied) {   }
  $retie_hash=1;      }
  &untiehash();              #
     }              # Code to figure out how many version entries should go in
     &tiehash('write');              # each of the four columns
     $hash{'old'}=1;              my $entries_per_col = 0;
     &untiehash();              my $num_entries = ($currentversion-$lastold);
     if ($retie_hash) { &tiehash(); }              if ($num_entries % 4 == 0) {
 }                  $entries_per_col = $num_entries/4;
               } else {
 sub is_hash_old {                  $entries_per_col = $num_entries/4 + 1;
     my $untie_hash=0;              }
     if (!$hashtied) {              my $entries_count = 0;
  $untie_hash=1;              $r->print('<td valign="top"><font size="-2">');
  &tiehash();              my $cols_output = 1;
     }              for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
     my $return=$hash{'old'};   my $url=$root.'.'.$prevvers.'.'.$extension;
     if ($untie_hash) { &untiehash(); }   $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
     return $return;    '">'.&mt('Version').' '.$prevvers.'</a> ('.
 }    &Apache::lonlocal::locallocaltime(
                                   &Apache::lonnet::metadata($url,
 sub changewarning {                                                            'lastrevisiondate')
     my ($r,$postexec,$message,$url)=@_;                                                              ).
     if (!&is_hash_old()) { return; }    ')');
     my $pathvar='folderpath';   if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
     my $path=&escape($env{'form.folderpath'});                      $r->print(' <a href="/adm/diff?filename='.
     if (!defined($url)) {        &Apache::lonnet::clutter($root.'.'.$extension).
  if (defined($env{'form.pagepath'})) {        '&versionone='.$prevvers.
     $pathvar='pagepath';        '">'.&mt('Diffs').'</a>');
     $path=&escape($env{'form.pagepath'});   }
     $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});   $r->print('</span><br />');
  }                  if (++$entries_count % $entries_per_col == 0) {
  $url='/adm/coursedocs?'.$pathvar.'='.$path;                      $r->print('</font></td>');
     }                      if ($cols_output != 4) {
     my $course_type = &Apache::loncommon::course_type();                          $r->print('<td valign="top"><font size="-2">');
     if (!defined($message)) {                          $cols_output++;
  $message='Changes will become active for your current session after [_1], or the next time you log in.';                      }
     }                  }
     $r->print("\n\n".      }
 '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".               while($cols_output++ < 4) {
 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.                  $r->print('</font></td><td><font>')
 '<input type="hidden" name="orgurl" value="'.$url.              }
 '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.      $r->print('</font></td></tr>'."\n");
 &mt($message,' <input type="hidden" name="'.   }
     $env{'request.role'}.'" value="1" /><input type="button" value="'.      }
     &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').      $r->print('</table></form>');
 $help{'Caching'}.'</span></h3></form>'."\n\n");      $r->print('<h1>'.&mt('Done').'.</h1>');
 }  
       &untiehash();
   }
 sub init_breadcrumbs {  
     my ($form,$text)=@_;  sub mark_hash_old {
     &Apache::lonhtmlcommon::clear_breadcrumbs();      my $retie_hash=0;
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",      if ($hashtied) {
     text=>"Edit ".&Apache::loncommon::course_type(),   $retie_hash=1;
     faq=>273,   &untiehash();
     bug=>'Instructor Interface',      }
                                             help => 'Docs_Adding_Course_Doc'});      &tiehash('write');
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',      $hash{'old'}=1;
     text=>$text,      &untiehash();
     faq=>273,      if ($retie_hash) { &tiehash(); }
     bug=>'Instructor Interface'});  }
 }  
   sub is_hash_old {
       my $untie_hash=0;
       if (!$hashtied) {
    $untie_hash=1;
 sub handler {   &tiehash();
     my $r = shift;      }
     &Apache::loncommon::content_type($r,'text/html');      my $return=$hash{'old'};
     $r->send_http_header;      if ($untie_hash) { &untiehash(); }
     return OK if $r->header_only;      return $return;
     my $type = &Apache::loncommon::course_type();  }
   
 # --------------------------------------------- Initialize help topics for this  sub changewarning {
     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',      my ($r,$postexec,$message,$url)=@_;
                'Adding_External_Resource','Navigate_Content',      if (!&is_hash_old()) { return; }
                'Adding_Folders','Docs_Overview', 'Load_Map',      my $pathvar='folderpath';
                'Supplemental','Score_Upload_Form','Adding_Pages',      my $path=&escape($env{'form.folderpath'});
                'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',      if (!defined($url)) {
                'Check_Resource_Versions','Verify_Content') {   if (defined($env{'form.pagepath'})) {
  $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);      $pathvar='pagepath';
     }      $path=&escape($env{'form.pagepath'});
     # Composite help files      $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(   }
     'Docs_About_Syllabus,Docs_Editing_Templated_Pages');   $url='/adm/coursedocs?'.$pathvar.'='.$path;
     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(      }
     'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');      my $course_type = &Apache::loncommon::course_type();
     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(      if (!defined($message)) {
     'Option_Response_Simple');   $message='Changes will become active for your current session after [_1], or the next time you log in.';
     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(      }
     'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');      $r->print("\n\n".
     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(  '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
   'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');  '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
     $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');  '<input type="hidden" name="orgurl" value="'.$url.
     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');  '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.
   &mt($message,' <input type="hidden" name="'.
 # does this user have privileges to modify docs      $env{'request.role'}.'" value="1" /><input type="button" value="'.
     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});      &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
   if ($allowed && $env{'form.verify'}) {  $help{'Caching'}.'</span></h3></form>'."\n\n");
       &init_breadcrumbs('verify','Verify Content');  }
       &verifycontent($r);  
   } elsif ($allowed && $env{'form.listsymbs'}) {  
       &init_breadcrumbs('listsymbs','List Symbs');  sub init_breadcrumbs {
       &list_symbs($r);      my ($form,$text)=@_;
   } elsif ($allowed && $env{'form.docslog'}) {      &Apache::lonhtmlcommon::clear_breadcrumbs();
       &init_breadcrumbs('docslog','Show Log');      &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
       &docs_change_log($r);      text=>"Edit ".&Apache::loncommon::course_type(),
   } elsif ($allowed && $env{'form.versions'}) {      faq=>273,
       &init_breadcrumbs('versions','Check/Set Resource Versions');      bug=>'Instructor Interface',
       &checkversions($r);                                              help => 'Docs_Adding_Course_Doc'});
   } elsif ($allowed && $env{'form.dumpcourse'}) {      &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');      text=>$text,
       &dumpcourse($r);      faq=>273,
   } elsif ($allowed && $env{'form.exportcourse'}) {      bug=>'Instructor Interface'});
       &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');  }
       &exportcourse($r);  
   } else {  
 # is this a standard course?  
   
     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);  sub handler {
     my $forcestandard = 0;      my $r = shift;
     my $forcesupplement;      &Apache::loncommon::content_type($r,'text/html');
     my $script='';      $r->send_http_header;
     my $showdoc=0;      return OK if $r->header_only;
     my $containertag;      my $type = &Apache::loncommon::course_type();
     my $uploadtag;  
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},  
     ['folderpath','pagepath',  # --------------------------------------------- Initialize help topics for this
      'pagesymb']);      foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
 # No folderpath, no pagepath, see if we have something stored                 'Adding_External_Resource','Navigate_Content',
     if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {                 'Adding_Folders','Docs_Overview', 'Load_Map',
         &Apache::loncommon::restore_course_settings('docs_folderpath',                 'Supplemental','Score_Upload_Form','Adding_Pages',
                                               {'folderpath' => 'scalar'});                 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
     }                 'Check_Resource_Versions','Verify_Content') {
     if (!$env{'form.folderpath'}) {   $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
         &Apache::loncommon::restore_course_settings('docs_folderpath',      }
                                               {'pagepath' => 'scalar'});      # Composite help files
     }      $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
     if ($env{'form.pagepath'}) {      'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
        $env{'form.folderpath'}='';      $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
     }      'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {      $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
         $env{'form.folderpath'} = 'supplemental&'.      'Option_Response_Simple');
                                   &escape(&mt('Supplemental '.$type.' Documents')).'&'.      $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                                   $env{'form.folderpath'};      'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
     }      $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
     &Apache::loncommon::store_course_settings('docs_folderpath',    'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
                                                 {'pagepath' => 'scalar',      $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
                                                  'folderpath' => 'scalar'});      $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
     if ($env{'form.folderpath'}) {  
  my (@folderpath)=split('&',$env{'form.folderpath'});  # does this user have privileges to modify docs
  $env{'form.foldername'}=&unescape(pop(@folderpath));      my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  $env{'form.folder'}=pop(@folderpath);    if ($allowed && $env{'form.verify'}) {
     }        &init_breadcrumbs('verify','Verify Content');
     if ($env{'form.pagepath'}) {        &verifycontent($r);
         my (@pagepath)=split('&',$env{'form.pagepath'});    } elsif ($allowed && $env{'form.listsymbs'}) {
         $env{'form.pagename'}=&unescape(pop(@pagepath));        &init_breadcrumbs('listsymbs','List Symbs');
         $env{'form.folder'}=pop(@pagepath);        &list_symbs($r);
         $containertag = '<input type="hidden" name="pagepath" value="" />'.    } elsif ($allowed && $env{'form.docslog'}) {
     '<input type="hidden" name="pagesymb" value="" />';        &init_breadcrumbs('docslog','Show Log');
         $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.        &docs_change_log($r);
     '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';    } elsif ($allowed && $env{'form.versions'}) {
     }        &init_breadcrumbs('versions','Check/Set Resource Versions');
     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {        &checkversions($r);
        $showdoc='/'.$1;    } elsif ($allowed && $env{'form.dumpcourse'}) {
     }        &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
     unless ($showdoc) { # got called from remote        &dumpcourse($r);
        if (($env{'form.folder'}=~/^(?:group|default)_/) ||     } elsif ($allowed && $env{'form.exportcourse'}) {
           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {        &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
            $forcestandard = 1;        &exportcourse($r);
        }     } else {
        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);  # is this a standard course?
   
        if ($allowed) {       my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);      my $forcestandard = 0;
          $script=&Apache::lonratedt::editscript('simple');       my $forcesupplement;
        }      my $script='';
     } else { # got called in sequence from course      my $showdoc=0;
        $allowed=0;      my $containertag;
     }      my $uploadtag;
   
 # get course data  
     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};      ['folderpath','pagepath',
        'pagesymb']);
 # get personal data   # No folderpath, no pagepath, see if we have something stored
     my $uname=$env{'user.name'};      if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
     my $udom=$env{'user.domain'};          &Apache::loncommon::restore_course_settings('docs_folderpath',
     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));                                                {'folderpath' => 'scalar'});
       }
 # graphics settings      if (!$env{'form.folderpath'}) {
           &Apache::loncommon::restore_course_settings('docs_folderpath',
     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");                                                {'pagepath' => 'scalar'});
       }
     if ($allowed) {      if ($env{'form.pagepath'}) {
  $script .= &editing_js($udom,$uname);         $env{'form.folderpath'}='';
     }      }
 # -------------------------------------------------------------------- Body tag      if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
     $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';          $env{'form.folderpath'} = 'supplemental&'.
  my @brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}];                                    &escape(&mt('Supplemental '.$type.' Documents')).'&'.
     $r->print(&Apache::loncommon::start_page("$type Documents", $script,                                    $env{'form.folderpath'};
      {'force_register' => $showdoc, bread_crumbs => @brcrum}).      }
       &Apache::loncommon::help_open_menu('','',273,'RAT'));      &Apache::loncommon::store_course_settings('docs_folderpath',
                                                     {'pagepath' => 'scalar',
   my %allfiles = ();                                                   'folderpath' => 'scalar'});
   my %codebase = ();      if ($env{'form.folderpath'}) {
   my ($upload_result,$upload_output);   my (@folderpath)=split('&',$env{'form.folderpath'});
   if ($allowed) {   $env{'form.foldername'}=&unescape(pop(@folderpath));
       if (($env{'form.uploaddoc.filename'}) &&   $env{'form.folder'}=pop(@folderpath);
   ($env{'form.cmd'}=~/^upload_(\w+)/)) {      }
 # Process file upload - phase one - upload and parse primary file.        if ($env{'form.pagepath'}) {
   undef($hadchanges);          my (@pagepath)=split('&',$env{'form.pagepath'});
           $upload_result = &process_file_upload(\$upload_output,$coursenum,          $env{'form.pagename'}=&unescape(pop(@pagepath));
  $coursedom,\%allfiles,          $env{'form.folder'}=pop(@pagepath);
  \%codebase,$1);          $containertag = '<input type="hidden" name="pagepath" value="" />'.
   if ($hadchanges) {      '<input type="hidden" name="pagesymb" value="" />';
       &mark_hash_old();          $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
   }      '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
           if ($upload_result eq 'phasetwo') {      }
               $r->print($upload_output);      if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
           }         $showdoc='/'.$1;
       } elsif ($env{'form.phasetwo'}) {      }
           my %newname = ();      unless ($showdoc) { # got called from remote
           my %origname = ();         if (($env{'form.folder'}=~/^(?:group|default)_/) ||
           my %attribs = ();            ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
           my $updateflag = 0;             $forcestandard = 1;
           my $residx = $env{'form.newidx'};         }
           my $primary_url = &unescape($env{'form.primaryurl'});         $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
 # Process file upload - phase two - gather secondary files.  
           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {         if ($allowed) {
               if ($env{'form.embedded_item_'.$i.'.filename'}) {           &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   my $javacodebase;           $script=&Apache::lonratedt::editscript('simple');
                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);         }
                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});      } else { # got called in sequence from course
                   if (exists($env{'form.embedded_codebase_'.$i})) {         $allowed=0;
                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});        }
                       $origname{$i} =~ s#^\Q$javacodebase\E/##;   
                   }  # get course data
                   my @attributes = ();      my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {      my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                       @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});  
                   } else {  # get personal data
                       @attributes = ($env{'form.embedded_attrib_'.$i});      my $uname=$env{'user.name'};
                   }      my $udom=$env{'user.domain'};
                   foreach my $attr (@attributes) {      my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                       push(@{$attribs{$i}},&unescape($attr));  
                   }  # graphics settings
                   if ($javacodebase) {  
                       $codebase{$i} = $javacodebase;      $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
                       $codebase{$i} =~ s#/$##;  
                       $updateflag = 1;      if ($allowed) {
                   }   $script .= &editing_js($udom,$uname);
               }      }
               unless ($newname{$i} eq $origname{$i}) {  # -------------------------------------------------------------------- Body tag
                   $updateflag = 1;      $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
               }      my $brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}];
           }      $r->print(&Apache::loncommon::start_page("$type Documents", $script,
 # Process file upload - phase three - modify primary file      {'force_register' => $showdoc,
           if ($updateflag) {                                       'bread_crumbs' => $brcrum}).
               my ($content,$rtncode);        &Apache::loncommon::help_open_menu('','',273,'RAT'));
               my $updateflag = 0;   
               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);    my %allfiles = ();
               if ($getstatus eq 'ok') {    my %codebase = ();
                   foreach my $item (keys(%newname)) {    my ($upload_result,$upload_output);
                       if ($newname{$item} ne $origname{$item}) {    if ($allowed) {
                           my $attrib_regexp = '';        if (($env{'form.uploaddoc.filename'}) &&
                           if (@{$attribs{$item}} > 1) {    ($env{'form.cmd'}=~/^upload_(\w+)/)) {
                               $attrib_regexp = join('|',@{$attribs{$item}});  # Process file upload - phase one - upload and parse primary file.  
                           } else {    undef($hadchanges);
                               $attrib_regexp = $attribs{$item}[0];            $upload_result = &process_file_upload(\$upload_output,$coursenum,
                           }   $coursedom,\%allfiles,
                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {   \%codebase,$1);
                           }     if ($hadchanges) {
                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;         &mark_hash_old();
                       }    }
                       if (exists($codebase{$item})) {            if ($upload_result eq 'phasetwo') {
                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs                $r->print($upload_output);
                       }            }
                   }        } elsif ($env{'form.phasetwo'}) {
 # Save edited file.            my %newname = ();
                   my $saveresult;            my %origname = ();
                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};            my %attribs = ();
                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};            my $updateflag = 0;
                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);            my $residx = $env{'form.newidx'};
               } else {            my $primary_url = &unescape($env{'form.primaryurl'});
                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);   # Process file upload - phase two - gather secondary files.
               }            for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
           }                if ($env{'form.embedded_item_'.$i.'.filename'}) {
       }                    my $javacodebase;
   }                    $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
                     $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
   unless ($showdoc ||  $upload_result eq 'phasetwo') {                    if (exists($env{'form.embedded_codebase_'.$i})) {
 # -----------------------------------------------------------------------------                        $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});  
        my %lt=&Apache::lonlocal::texthash(                        $origname{$i} =~ s#^\Q$javacodebase\E/##;
                 'uplm' => 'Upload a new main '.lc($type).' document',                    }
                 'upls' => 'Upload a new supplemental '.lc($type).' document',                    my @attributes = ();
                 'impp' => 'Import a document',                    if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
                 'pubd' => 'Published documents',                        @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
  'copm' => 'All documents out of a published map into this folder',                    } else {
                 'spec' => 'Special documents',                        @attributes = ($env{'form.embedded_attrib_'.$i});
                 'upld' => 'Upload Document',                    }
                 'srch' => 'Search',                    foreach my $attr (@attributes) {
                 'impo' => 'Import',                        push(@{$attribs{$i}},&unescape($attr));
  'book' => 'Import Bookmarks',                    }
                 'selm' => 'Select Map',                    if ($javacodebase) {
                 'load' => 'Load Map',                        $codebase{$i} = $javacodebase;
                 'reco' => 'Recover Deleted Resources',                        $codebase{$i} =~ s#/$##;
                 'newf' => 'New Folder',                        $updateflag = 1;
                 'newp' => 'New Composite Page',                    }
                 'extr' => 'External Resource',                }
                 'syll' => 'Syllabus',                unless ($newname{$i} eq $origname{$i}) {
                 'navc' => 'Navigate Contents',                    $updateflag = 1;
                 'sipa' => 'Simple Page',                }
                 'sipr' => 'Simple Problem',            }
                 'drbx' => 'Drop Box',  # Process file upload - phase three - modify primary file
                 'scuf' => 'Score Upload Form',            if ($updateflag) {
                 'bull' => 'Bulletin Board',                my ($content,$rtncode);
                 'mypi' => 'My Personal Info',                my $updateflag = 0;
                 'grpo' => 'Group Files',                my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
                 'rost' => 'Course Roster',                if ($getstatus eq 'ok') {
  'abou' => 'About User',                    foreach my $item (keys(%newname)) {
                 'imsf' => 'Import IMS package',                        if ($newname{$item} ne $origname{$item}) {
                 'file' =>  'File',                            my $attrib_regexp = '';
                 'title' => 'Title',                            if (@{$attribs{$item}} > 1) {
                 'comment' => 'Comment',                                $attrib_regexp = join('|',@{$attribs{$item}});
                 'parse' => 'If HTML file, upload embedded images/multimedia files'                            } else {
   );                                $attrib_regexp = $attribs{$item}[0];
 # -----------------------------------------------------------------------------                            }
     if ($allowed) {                            if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
  &update_paste_buffer($coursenum,$coursedom);                            }
        my $dumpbut=&dumpbutton();                            $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
        my $exportbut=&exportbutton();                        }
        my %lt=&Apache::lonlocal::texthash(                        if (exists($codebase{$item})) {
  'vc' => 'Verify Content',                            $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
  'cv' => 'Check/Set Resource Versions',                        }
  'ls' => 'List Symbs',                    }
                                          'sl' => 'Show Log'  # Save edited file.
   );                    my $saveresult;
                     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
        my $folderpath=$env{'form.folderpath'};                    my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
        if (!$folderpath) {                    my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
    if ($env{'form.folder'} eq '' ||                } else {
        $env{'form.folder'} eq 'supplemental') {                    &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
        $folderpath='default&'.                }
    &escape(&mt('Main '.$type.' Documents'));            }
    }        }
        }    }
        unless ($env{'form.pagepath'}) {  
            $containertag = '<input type="hidden" name="folderpath" value="" />';    unless ($showdoc ||  $upload_result eq 'phasetwo') {
            $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';  # -----------------------------------------------------------------------------
        }         my %lt=&Apache::lonlocal::texthash(
                   'uplm' => 'Upload a new main '.lc($type).' document',
        $r->print(<<ENDCOURSEVERIFY);                  'upls' => 'Upload a new supplemental '.lc($type).' document',
 <form name="renameform" method="post" action="/adm/coursedocs">                  'impp' => 'Import a document',
   <input type="hidden" name="title" />                  'pubd' => 'Published Documents',
   <input type="hidden" name="cmd" />   'copm' => 'All documents out of a published map into this folder',
   <input type="hidden" name="markcopy" />                  'upld' => 'Upload Document',
   <input type="hidden" name="copyfolder" />                  'srch' => 'Search',
   $containertag                  'impo' => 'Import',
 </form>   'book' => 'Import Bookmarks',
 <form name="simpleedit" method="post" action="/adm/coursedocs">                  'selm' => 'Select Map',
   <input type="hidden" name="importdetail" value="" />                  'load' => 'Load Map',
   $uploadtag                  'reco' => 'Recover Deleted Resources',
 </form>                  'newf' => 'New Folder',
 <form action="/adm/coursedocs" method="post" name="courseverify">                  'newp' => 'New Composite Page',
   <div class="LC_docs_course_commands">                  'extr' => 'External Resource',
                   'syll' => 'Syllabus',
       <div>                  'navc' => 'Navigate Contents',
         <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}                  'sipa' => 'Simple Page',
       </div>                  'sipr' => 'Simple Problem',
       <div>                  'drbx' => 'Drop Box',
         <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}                  'scuf' => 'Score Upload Form',
       </div>                  'bull' => 'Bulletin Board',
         $dumpbut                  'mypi' => 'My Personal Info',
         $exportbut                  'grpo' => 'Group Files',
       <div>                  'rost' => 'Course Roster',
         <input type="submit" name="listsymbs" value="$lt{'ls'}" />   'abou' => 'About User',
       </div>                  'imsf' => 'Import IMS package',
       <div>                  'file' =>  'File',
         <input type="hidden" name="folder" value="$env{'form.folder'}" />                  'title' => 'Title',
         <input type="submit" name="docslog" value="$lt{'sl'}" />                  'comment' => 'Comment',
       </div>                  'parse' => 'Upload embedded images/multimedia files if HTML file!',
   </div>   'nd' => 'New Document',
 </form>   'pm' => 'Published Map',
 <div style="clear: both; height: 0px;">&nbsp;</div>   'sd' => 'Special Document',
 ENDCOURSEVERIFY   'mo' => 'More Options',
        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',   'hao' => 'Hide all Options'
      &mt('Editing the Table of Contents for your '.$type)));    );
     }  # -----------------------------------------------------------------------------
 # --------------------------------------------------------- Standard documents   my $fileupload=(<<FIUP);
     $r->print('<table class="LC_docs_documents">');   $lt{'file'}:<br />
    <input type="file" name="uploaddoc" size="40" />
     if (($standard) && ($allowed) && (!$forcesupplement)) {  FIUP
  $r->print('<tr><td class="LC_docs_document">');  
 #  '<h2>'.&mt('Main Course Documents').   my $checkbox=(<<CHBO);
 #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');   <!-- <label>$lt{'parse'}?
        my $folder=$env{'form.folder'};   <input type="checkbox" name="parserflag" />
        if ($folder eq '' || $folder eq 'supplemental') {   </label> -->
            $folder='default';   <label>
    $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));   <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
            $uploadtag = '<input type="hidden" name="folderpath" value="'.   </label>
        &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';  CHBO
        }  
        my $postexec='';   my $fileuploadform=(<<FUFORM);
        if ($folder eq 'default') {   <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
    $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');   $fileupload
        } else {   <br />
            #$postexec='self.close();';   $lt{'title'}:<br />
        }   <input type="text" size="50" name="comment" />
        $hadchanges=0;   $uploadtag
        my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,   <input type="hidden" name="cmd" value="upload_default" />
    $upload_output,$type);   <br />
        if ($error) {   <span class="LC_nobreak">
    $r->print('<p><span class="LC_error">'.$error.'</span></p>');   $checkbox
        }   </span>
        if ($hadchanges) {   <br />
    &mark_hash_old();   <br />
        }   <span class="LC_nobreak">
        &changewarning($r,$postexec);   <input type="submit" value="$lt{'upld'}" />
        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.   $help{'Uploading_From_Harddrive'}
                      '.sequence';   </span>
        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.   </form>
                      '.page';  FUFORM
  my $container='sequence';  
  if ($env{'form.pagepath'}) {   my $simpleeditdefaultform=(<<SEDFFORM);
     $container='page';   <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
  }   $lt{'pubd'}<br />
  my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;   $uploadtag
        $r->print(<<ENDFORM);   <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />
 <table class="LC_docs_adddocs">   <br />
 <tr>   <span class="LC_nobreak">
 <th>$lt{'uplm'}</th>   <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />
 <th>$lt{'impp'}</th>   $help{'Importing_LON-CAPA_Resource'}
 <th>$lt{'spec'}</th>   </span>
 </tr>   <br />
 <tr>   <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
 <td>   <hr />
 $lt{'file'}:<br />   <p>
 <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">   $lt{'copm'}<br />
 <input type="file" name="uploaddoc" size="40" />   <input type="text" size="40" name="importmap" /><br />
 <br />   <span class="LC_nobreak"><input type="button"
 $lt{'title'}:<br />   onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 <input type="text" size="50" name="comment" />   value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
 $uploadtag   $help{'Load_Map'}</span>
 <input type="hidden" name="cmd" value="upload_default" />   </p>
 <br />   </form>
 <span class="LC_nobreak">  SEDFFORM
 <label>$lt{'parse'}?  
 <input type="checkbox" name="parserflag" checked="checked" />   my $extresourcesform=(<<ERFORM);
 </label>   <form action="/adm/coursedocs" method="post" name="newext">
 </span>   $uploadtag
 <br />   <input type="hidden" name="importdetail" value="" />
 <br />   <span class="LC_nobreak">
 <span class="LC_nobreak">   <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 <input type="submit" value="$lt{'upld'}" />   value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
  $help{'Uploading_From_Harddrive'}   </span>
 </span>   </form>
 </form>  ERFORM
 </td>  
 <td>      if ($allowed) {
 <form action="/adm/coursedocs" method="post" name="simpleeditdefault">   &update_paste_buffer($coursenum,$coursedom);
 $lt{'pubd'}<br />         my $dumpbut=&dumpbutton();
 $uploadtag         my $exportbut=&exportbutton();
 <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />         my %lt=&Apache::lonlocal::texthash(
 <br />   'vc' => 'Verify Content',
 <span class="LC_nobreak">   'cv' => 'Check/Set Resource Versions',
 <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />   'ls' => 'List Symbs',
 $help{'Importing_LON-CAPA_Resource'}                                           'sl' => 'Show Log'
 </span>    );
 <br />  
 <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />         my $folderpath=$env{'form.folderpath'};
 <hr />         if (!$folderpath) {
 <p>     if ($env{'form.folder'} eq '' ||
 $lt{'copm'}<br />         $env{'form.folder'} eq 'supplemental') {
 <input type="text" size="40" name="importmap" /><br />         $folderpath='default&'.
 <span class="LC_nobreak"><input type="button"      &escape(&mt('Main '.$type.' Documents'));
 onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"     }
 value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />         }
 $help{'Load_Map'}</span>         unless ($env{'form.pagepath'}) {
 </p>             $containertag = '<input type="hidden" name="folderpath" value="" />';
 </form>             $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
 <hr />         }
 <form action="/adm/groupsort" method="post" name="recover">  
 <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />         $r->print(<<ENDCOURSEVERIFY);
 </form>  <form name="renameform" method="post" action="/adm/coursedocs">
 ENDFORM    <input type="hidden" name="title" />
        unless ($env{'form.pagepath'}) {    <input type="hidden" name="cmd" />
    $r->print(<<ENDFORM);    <input type="hidden" name="markcopy" />
 <hr />    <input type="hidden" name="copyfolder" />
 <form action="/adm/coursedocs" method="post" name="newext">    $containertag
 $uploadtag  </form>
 <input type="hidden" name="importdetail" value="" />  <form name="simpleedit" method="post" action="/adm/coursedocs">
 <span class="LC_nobreak">    <input type="hidden" name="importdetail" value="" />
 <input name="newext" type="button" onClick="javascript:makenewext('newext');"    $uploadtag
 value="$lt{'extr'}" /> $help{'Adding_External_Resource'}  </form>
 </span>  <form action="/adm/coursedocs" method="post" name="courseverify">
 </form>    <div class="LC_docs_course_commands">
 <br /><form action="/adm/imsimportdocs" method="post" name="ims">  
 <input type="hidden" name="folder" value="$folder" />        <div>
 <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />          <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
 </form>        </div>
 ENDFORM        <div>
        }          <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
        $r->print('</td><td>');        </div>
        unless ($env{'form.pagepath'}) {          $dumpbut
    my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');          $exportbut
            $r->print(<<ENDFORM);        <div>
 <br /><form action="/adm/coursedocs" method="post" name="newfolder">          <input type="submit" name="listsymbs" value="$lt{'ls'}" />
 <input type="hidden" name="folderpath" value="$path" />        </div>
 <input type="hidden" name="importdetail" value="" />        <div>
 <span class="LC_nobreak">          <input type="hidden" name="folder" value="$env{'form.folder'}" />
 <input name="newfolder" type="button"          <input type="submit" name="docslog" value="$lt{'sl'}" />
 onClick="javascript:makenewfolder(this.form,'$folderseq');"        </div>
 value="$lt{'newf'}" />$help{'Adding_Folders'}    </div>
 </span>  </form>
 </form>  <div style="clear: both; height: 0px;">&nbsp;</div>
 <br /><form action="/adm/coursedocs" method="post" name="newpage">  ENDCOURSEVERIFY
 <input type="hidden" name="folderpath" value="$path" />         $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 <input type="hidden" name="importdetail" value="" />       &mt('Editing the Table of Contents for your '.$type)));
 <span class="LC_nobreak">      }
 <input name="newpage" type="button"  # --------------------------------------------------------- Standard documents
 onClick="javascript:makenewpage(this.form,'$pageseq');"      $r->print('<table class="LC_docs_documents">');
 value="$lt{'newp'}" />$help{'Adding_Pages'}  
 </span>      if (($standard) && ($allowed) && (!$forcesupplement)) {
 </form>   $r->print('<tr><td class="LC_docs_document">');
 <br /><form action="/adm/coursedocs" method="post" name="newsyl">  #  '<h2>'.&mt('Main Course Documents').
 $uploadtag  #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 <input type="hidden" name="importdetail"          my $folder=$env{'form.folder'};
 value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />         if ($folder eq '' || $folder eq 'supplemental') {
 <span class="LC_nobreak">             $folder='default';
 <input name="newsyl" type="submit" value="$lt{'syll'}" />      $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
  $help{'Syllabus'}             $uploadtag = '<input type="hidden" name="folderpath" value="'.
 </span>         &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
 </form>         }
 <br /><form action="/adm/coursedocs" method="post" name="newnav">         my $postexec='';
 $uploadtag         if ($folder eq 'default') {
 <input type="hidden" name="importdetail"      $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
 value="$lt{'navc'}=/adm/navmaps" />         } else {
 <span class="LC_nobreak">             #$postexec='self.close();';
 <input name="newnav" type="submit" value="$lt{'navc'}" />         }
 $help{'Navigate_Content'}         $hadchanges=0;
 </span>         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,
 </form>     $upload_output,$type);
 <br /><form action="/adm/coursedocs" method="post" name="newsmppg">         if ($error) {
 $uploadtag     $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 <input type="hidden" name="importdetail" value="" />         }
 <span class="LC_nobreak">         if ($hadchanges) {
 <input name="newsmppg" type="button" value="$lt{'sipa'}"     &mark_hash_old();
 onClick="javascript:makesmppage();" /> $help{'Simple Page'}         }
 </span>         &changewarning($r,$postexec);
 </form>         my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">                       '.sequence';
 $uploadtag         my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 <input type="hidden" name="importdetail" value="" />                       '.page';
 <span class="LC_nobreak">   my $container='sequence';
 <input name="newsmpproblem" type="button" value="$lt{'sipr'}"   if ($env{'form.pagepath'}) {
 onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}      $container='page';
 </span>   }
 </form>   my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
 <br /><form action="/adm/coursedocs" method="post" name="newdropbox">  
 $uploadtag        
 <input type="hidden" name="importdetail" value="" />  
 <span class="LC_nobreak">             my $recoverform=(<<RFORM);
 <input name="newdropbox" type="button" value="$lt{'drbx'}"   <form action="/adm/groupsort" method="post" name="recover">
 onClick="javascript:makedropbox();" />   <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
 </span>            </form>
 </form>   RFORM
 <br /><form action="/adm/coursedocs" method="post" name="newexamupload">  
 $uploadtag   my $imspform=(<<IMSPFORM);
 <input type="hidden" name="importdetail" value="" />   <form action="/adm/imsimportdocs" method="post" name="ims">
 <span class="LC_nobreak">   <input type="hidden" name="folder" value="$folder" />
 <input name="newexamupload" type="button" value="$lt{'scuf'}"   <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
 onClick="javascript:makeexamupload();" />   </form>
 $help{'Score_Upload_Form'}  IMSPFORM
 </span>  
 </form>   my $newnavform=(<<NNFORM);
 <br /><form action="/adm/coursedocs" method="post" name="newbul">   <form action="/adm/coursedocs" method="post" name="newnav">
 $uploadtag   $uploadtag
 <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail"
 <span class="LC_nobreak">   value="$lt{'navc'}=/adm/navmaps" />
 <input name="newbulletin" type="button" value="$lt{'bull'}"   <span class="LC_nobreak">
 onClick="javascript:makebulboard();" />   <input name="newnav" type="submit" value="$lt{'navc'}" />
 $help{'Bulletin Board'}   $help{'Navigate_Content'}
 </span>   </span>
 </form>   </form>
 <br /><form action="/adm/coursedocs" method="post" name="newaboutme">  NNFORM
 $uploadtag   my $newsmppageform=(<<NSPFORM);
 <input type="hidden" name="importdetail"    <form action="/adm/coursedocs" method="post" name="newsmppg">
 value="$plainname=/adm/$udom/$uname/aboutme" />   $uploadtag
 <span class="LC_nobreak">   <input type="hidden" name="importdetail" value="" />
 <input name="newaboutme" type="submit" value="$lt{'mypi'}" />   <span class="LC_nobreak">
 $help{'My Personal Info'}   <input name="newsmppg" type="button" value="$lt{'sipa'}"
 </span>   onClick="javascript:makesmppage();" /> $help{'Simple Page'}
 </form>   </span>
 <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">   </form>
 $uploadtag  NSPFORM
 <input type="hidden" name="importdetail" value="" />  
 <span class="LC_nobreak">   my $newsmpproblemform=(<<NSPROBFORM);
 <input name="newaboutsomeone" type="button" value="$lt{'abou'}"    <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 onClick="javascript:makeabout();" />   $uploadtag
 </span>   <input type="hidden" name="importdetail" value="" />
 </form>   <span class="LC_nobreak">
 <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">   <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 $uploadtag   onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 <input type="hidden" name="importdetail"   </span>
 value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />   </form>
 <span class="LC_nobreak">  
 <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />  NSPROBFORM
 $help{'Group Files'}  
 </span>   my $newdropboxform=(<<NDBFORM);
 </form>   <form action="/adm/coursedocs" method="post" name="newdropbox">
 <br /><form action="/adm/coursedocs" method="post" name="newroster">   $uploadtag      
 $uploadtag   <input type="hidden" name="importdetail" value="" />
 <input type="hidden" name="importdetail"    <span class="LC_nobreak">          
 value="$lt{'rost'}=/adm/viewclasslist" />   <input name="newdropbox" type="button" value="$lt{'drbx'}"
 <span class="LC_nobreak">   onClick="javascript:makedropbox();" />
 <input name="newroster" type="submit" value="$lt{'rost'}" />   </span>        
 $help{'Course Roster'}   </form>
 </span>  NDBFORM
 </form>  
 ENDFORM   my $newexuploadform=(<<NEXUFORM);
        }   <form action="/adm/coursedocs" method="post" name="newexamupload">
        if ($env{'form.pagepath'}) {   $uploadtag
            $r->print(<<ENDBLOCK);   <input type="hidden" name="importdetail" value="" />
 <form action="/adm/coursedocs" method="post" name="newsmpproblem">   <span class="LC_nobreak">
 $uploadtag   <input name="newexamupload" type="button" value="$lt{'scuf'}"
 <input type="hidden" name="importdetail" value="" />   onClick="javascript:makeexamupload();" />
 <span class="LC_nobreak">   $help{'Score_Upload_Form'}
 <input name="newsmpproblem" type="button" value="$lt{'sipr'}"   </span>
 onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}   </form>
 </span>  NEXUFORM
 </form>  
 <br /><form action="/adm/coursedocs" method="post" name="newexamupload">   my $newbulform=(<<NBFORM);
 $uploadtag   <form action="/adm/coursedocs" method="post" name="newbul">
 <input type="hidden" name="importdetail" value="" />   $uploadtag
 <span class="LC_nobreak">   <input type="hidden" name="importdetail" value="" />
 <input name="newexamupload" type="button" value="$lt{'scuf'}"   <span class="LC_nobreak">
 onClick="javascript:makeexamupload();" />   <input name="newbulletin" type="button" value="$lt{'bull'}"
 $help{'Score_Upload_Form'}   onClick="javascript:makebulboard();" />
 </span>   $help{'Bulletin Board'}
 </form>   </span>
 ENDBLOCK   </form>
        }  NBFORM
        $r->print('</td></tr>'."\n".  
 '</table>');   my $newaboutmeform=(<<NAMFORM);
        $r->print('</td></tr>');   <form action="/adm/coursedocs" method="post" name="newaboutme">
     }   $uploadtag
 # ----------------------------------------------------- Supplemental documents   <input type="hidden" name="importdetail"
     if (!$forcestandard) {   value="$plainname=/adm/$udom/$uname/aboutme" />
        $r->print('<tr><td class="LC_docs_document">');   <span class="LC_nobreak">
 # '<h2>'.&mt('Supplemental Course Documents').   <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');   $help{'My Personal Info'}
        my $folder=$env{'form.folder'};   </span>
        unless ($folder=~/^supplemental/) {   </form>
    $folder='supplemental';  NAMFORM
        }  
        if ($folder =~ /^supplemental$/ &&   my $newaboutsomeoneform=(<<NASOFORM);
    (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {   <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
           $env{'form.folderpath'} = 'supplemental&'.   $uploadtag
                                     &escape(&mt('Supplemental '.$type.' Documents'));   <input type="hidden" name="importdetail" value="" />
        }   <span class="LC_nobreak">
        my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);   <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
        if ($error) {   onClick="javascript:makeabout();" />
    $r->print('<p><span class="LC_error">'.$error.'</span></p>');   </span>
        }   </form>
        if ($allowed) {  NASOFORM
    my $folderseq=  
        '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.  
        '.sequence';   my $newrosterform=(<<NROSTFORM);
    <form action="/adm/coursedocs" method="post" name="newroster">
    my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');   $uploadtag
    $r->print(<<ENDSUPFORM);   <input type="hidden" name="importdetail"
 <table class="LC_docs_adddocs"><tr>   value="$lt{'rost'}=/adm/viewclasslist" />
 <th>$lt{'upls'}</th>   <span class="LC_nobreak">
 <th>$lt{'spec'}</th>   <input name="newroster" type="submit" value="$lt{'rost'}" />
 </tr>   $help{'Course Roster'}
 <tr><td>   </span>
 <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">   </form>
 <input type="file" name="uploaddoc" size="40" />  NROSTFORM
 <br />  
 <br />         $r->print(<<ENDFORM);
 <span class="LC_nobreak">  
 <label>$lt{'parse'}?  <ul class="LC_TabContent">
 <input type="checkbox" name="parserflag" />  <li>$lt{'nd'}</li>
 </label>  <li>$lt{'pm'}</li>
 </span>  <li>$lt{'pubd'}</li>
 <br /><br />  <li>$lt{'sd'}</li>
 $lt{'comment'}:<br />  <li>$lt{'mo'}</li>
 <textarea cols=50 rows=4 name='comment'>  <li>$lt{'hao'}</li>
 </textarea>  </ul>
 <br />  
 <input type="hidden" name="folderpath" value="$path" />  <table class="LC_docs_adddocs">
 <input type="hidden" name="cmd" value="upload_supplemental" />  <!-- <tr>
 <span class="LC_nobreak">  <th>$lt{'uplm'}</th>
 <input type="submit" value="$lt{'upld'}" />  <th>$lt{'impp'}</th>
  $help{'Uploading_From_Harddrive'}  <th>$lt{'spec'}</th>
 </span>  </tr> -->
 </form>  <tr>
 </td>  <td>
 <td>  $fileuploadform
 <form action="/adm/coursedocs" method="post" name="supnewfolder">  </td>
 <input type="hidden" name="folderpath" value="$path" />  <td>
 <input type="hidden" name="importdetail" value="" />  $simpleeditdefaultform
 <span class="LC_nobreak">  <hr />
 <input name="newfolder" type="button"  $recoverform
 onClick="javascript:makenewfolder(this.form,'$folderseq');"  ENDFORM
 value="$lt{'newf'}" /> $help{'Adding_Folders'}         unless ($env{'form.pagepath'}) {
 </span>     $r->print(<<ENDFORM);
 </form>  <hr />
 <br /><form action="/adm/coursedocs" method="post" name="supnewext">  $extresourcesform
 <input type="hidden" name="folderpath" value="$path" />   <br />
 <input type="hidden" name="importdetail" value="" />  $imspform
 <span class="LC_nobreak">  ENDFORM
 <input name="newext" type="button"          }
 onClick="javascript:makenewext('supnewext');"         $r->print('</td><td>');
 value="$lt{'extr'}" /> $help{'Adding_External_Resource'}         unless ($env{'form.pagepath'}) {
 </span>     my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 </form>  
 <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">  
 <input type="hidden" name="folderpath" value="$path" />  
 <input type="hidden" name="importdetail"    my $newpageform=(<<NPFORM);
 value="Syllabus=/public/$coursedom/$coursenum/syllabus" />   <form action="/adm/coursedocs" method="post" name="newpage">
 <span class="LC_nobreak">   <input type="hidden" name="folderpath" value="$path" />
 <input name="newsyl" type="submit" value="$lt{'syll'}" />   <input type="hidden" name="importdetail" value="" />
 $help{'Syllabus'}   <span class="LC_nobreak">
 </span>   <input name="newpage" type="button"
 </form>   onClick="javascript:makenewpage(this.form,'$pageseq');"
 <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">   value="$lt{'newp'}" />$help{'Adding_Pages'}
 <input type="hidden" name="folderpath" value="$path" />   </span>
 <input type="hidden" name="importdetail"    </form>
 value="$plainname=/adm/$udom/$uname/aboutme" />  NPFORM
 <span class="LC_nobreak">  
 <input name="newaboutme" type="submit" value="$lt{'mypi'}" />   my $newfolderform=(<<NFFORM);
 $help{'My Personal Info'}   <form action="/adm/coursedocs" method="post" name="newfolder">
 </span>   <input type="hidden" name="folderpath" value="$path" />
 </form>   <input type="hidden" name="importdetail" value="" />
 </td></tr>   <span class="LC_nobreak">
 </table></td></tr>   <input name="newfolder" type="button"
 ENDSUPFORM   onClick="javascript:makenewfolder(this.form,'$folderseq');"
        }   value="$lt{'newf'}" />$help{'Adding_Folders'}
     }   </span>
     $r->print('</table>');   </form>
     if ($allowed) {  NFFORM
  $r->print('  
 <form method="post" name="extimport" action="/adm/coursedocs">   my $newsylform=(<<NSYLFORM);
   <input type="hidden" name="title" />   <form action="/adm/coursedocs" method="post" name="newsyl">
   <input type="hidden" name="url" />   $uploadtag
   <input type="hidden" name="useform" />   <input type="hidden" name="importdetail"
   <input type="hidden" name="residx" />   value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
 </form>');   <span class="LC_nobreak">
     }   <input name="newsyl" type="submit" value="$lt{'syll'}" />
   } else {   $help{'Syllabus'}
       unless ($upload_result eq 'phasetwo') {   </span>
 # -------------------------------------------------------- This is showdoc mode   </form>
           $r->print("<h1>".&mt('Uploaded Document').' - '.  NSYLFORM
  &Apache::lonnet::gettitle($r->uri).'</h1><p>'.  
 &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".   my $newgroupfileform=(<<NGFFORM);
           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');   <form action="/adm/coursedocs" method="post" name="newgroupfiles">
       }   $uploadtag
   }   <input type="hidden" name="importdetail"
  }   value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
  $r->print(&Apache::loncommon::end_page());   <span class="LC_nobreak">
  return OK;   <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
 }    $help{'Group Files'}
    </span>
    </form>
 sub editing_js {  NGFFORM
     my ($udom,$uname) = @_;  
     my $now = time();  
     my %lt = &Apache::lonlocal::texthash(             $r->print(<<ENDFORM);
                                           p_mnf => 'Name of New Folder',  <br />
                                           t_mnf => 'New Folder',  $newfolderform
                                           p_mnp => 'Name of New Page',  <br />
                                           t_mnp => 'New Page',  $newpageform
                                           p_mxu => 'Title for the Uploaded Score',  <br />
                                           p_msp => 'Title for the Page',  $newsylform
                                           p_msb => 'Title for the Problem',  <br />
                                           p_mdb => 'Title for the Drop Box',  $newnavform
                                           p_mbb => 'Title for the Bulletin Board',  <br />
                                           p_mab => "Enter user:domain for User's 'About Me' Page",  $newsmppageform
                                           p_mab2 => "About [_99]",  <br />
                                           p_mab_alrt1 => 'Not a valid user:domain',  $newsmpproblemform
                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',  <br />
                                           p_chn => 'New Title',  $newdropboxform
                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',  <br />
                                           p_rmr2a => 'Remove[_99]',  $newexuploadform
                                           p_rmr2b => '?[_99]',  <br />
                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',  $newbulform
                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',  <br />
                                           p_ctr2a => 'Cut[_98]',  $newaboutmeform
                                           p_ctr2b => '?[_98]'  <br />
                                         );  $newaboutsomeoneform
   <br />
     return <<ENDNEWSCRIPT;  $newgroupfileform
 function makenewfolder(targetform,folderseq) {  <br />
     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');  $newrosterform
     if (foldername) {  ENDFORM
        targetform.importdetail.value=escape(foldername)+"="+folderseq;         }
         targetform.submit();         if ($env{'form.pagepath'}) {
     }             $r->print(<<ENDBLOCK);
 }  $newsmpproblemform
   <br />
 function makenewpage(targetform,folderseq) {  $newexuploadform
     var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');  ENDBLOCK
     if (pagename) {         }
         targetform.importdetail.value=escape(pagename)+"="+folderseq;         $r->print('</td></tr>'."\n".
         targetform.submit();  '</table>');
     }         $r->print('</td></tr>');
 }      }
   # ----------------------------------------------------- Supplemental documents
 function makenewext(targetname) {      if (!$forcestandard) {
     this.document.forms.extimport.useform.value=targetname;         $r->print('<tr><td class="LC_docs_document">');
     this.document.forms.extimport.title.value='';  # '<h2>'.&mt('Supplemental Course Documents').
     this.document.forms.extimport.url.value='';  #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
     this.document.forms.extimport.residx.value='';         my $folder=$env{'form.folder'};
     window.open('/adm/rat/extpickframe.html');         unless ($folder=~/^supplemental/) {
 }     $folder='supplemental';
          }
 function edittext(targetname,residx,title,url) {         if ($folder =~ /^supplemental$/ &&
     this.document.forms.extimport.useform.value=targetname;     (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
     this.document.forms.extimport.residx.value=residx;            $env{'form.folderpath'} = 'supplemental&'.
     this.document.forms.extimport.url.value=url;                                      &escape(&mt('Supplemental '.$type.' Documents'));
     this.document.forms.extimport.title.value=title;         }
     window.open('/adm/rat/extpickframe.html');         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
 }         if ($error) {
      $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 function makeexamupload() {         }
    var title=prompt('$lt{"p_mxu"}');         if ($allowed) {
    if (title) {      my $folderseq=
     this.document.forms.newexamupload.importdetail.value=         '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
  escape(title)+'=/res/lib/templates/examupload.problem';         '.sequence';
     this.document.forms.newexamupload.submit();  
    }     my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 }  
    my $supupdocform=(<<SUPDOCFORM);
 function makesmppage() {   <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
    var title=prompt('$lt{"p_msp"}');   $fileupload
    if (title) {    <br />
     this.document.forms.newsmppg.importdetail.value=   <br />
  escape(title)+'=/adm/$udom/$uname/$now/smppg';   <span class="LC_nobreak">
     this.document.forms.newsmppg.submit();   $checkbox
    }   </span>
 }   <br /><br />
    $lt{'comment'}:<br />
 function makesmpproblem() {   <textarea cols=50 rows=4 name='comment'>
    var title=prompt('$lt{"p_msb"}');   </textarea>
    if (title) {    <br />
     this.document.forms.newsmpproblem.importdetail.value=   <input type="hidden" name="folderpath" value="$path" />
  escape(title)+'=/res/lib/templates/simpleproblem.problem';   <input type="hidden" name="cmd" value="upload_supplemental" />
     this.document.forms.newsmpproblem.submit();   <span class="LC_nobreak">
    }   <input type="submit" value="$lt{'upld'}" />
 }   $help{'Uploading_From_Harddrive'}
    </span>
 function makedropbox() {   </form>
    var title=prompt('$lt{"p_mdb"}');  SUPDOCFORM
    if (title) {   
     this.document.forms.newdropbox.importdetail.value=   my $supnewfolderform=(<<SNFFORM);
         escape(title)+'=/res/lib/templates/DropBox.problem';   <form action="/adm/coursedocs" method="post" name="supnewfolder">
     this.document.forms.newdropbox.submit();   <input type="hidden" name="folderpath" value="$path" />
    }   <input type="hidden" name="importdetail" value="" />
 }   <span class="LC_nobreak">
    <input name="newfolder" type="button"
 function makebulboard() {   onClick="javascript:makenewfolder(this.form,'$folderseq');"
    var title=prompt('$lt{"p_mbb"}');   value="$lt{'newf'}" /> $help{'Adding_Folders'}
    if (title) {   </span>
     this.document.forms.newbul.importdetail.value=   </form>
  escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';  SNFFORM
     this.document.forms.newbul.submit();  
    }  
 }   my $supnewextform=(<<SNEFORM);
    <form action="/adm/coursedocs" method="post" name="supnewext">
 function makeabout() {   <input type="hidden" name="folderpath" value="$path" />
    var user=prompt("$lt{'p_mab'}");   <input type="hidden" name="importdetail" value="" />
    if (user) {   <span class="LC_nobreak">
        var comp=new Array();   <input name="newext" type="button"
        comp=user.split(':');   onClick="javascript:makenewext('supnewext');"
        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {   value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
    if ((comp[0]) && (comp[1])) {   </span>
        this.document.forms.newaboutsomeone.importdetail.value=   </form>
    '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';  SNEFORM
        this.document.forms.newaboutsomeone.submit();  
    } else {   my $supnewsylform=(<<SNSFORM);
                alert("$lt{'p_mab_alrt1'}");   <form action="/adm/coursedocs" method="post" name="supnewsyl">
            }   <input type="hidden" name="folderpath" value="$path" />
        } else {   <input type="hidden" name="importdetail"
            alert("$lt{'p_mab_alrt2'}");   value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
        }   <span class="LC_nobreak">
    }   <input name="newsyl" type="submit" value="$lt{'syll'}" />
 }   $help{'Syllabus'}
    </span>
 function makeims() {   </form>
     var caller = document.forms.ims.folder.value;  SNSFORM
     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";  
     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");   my $supnewaboutmeform=(<<SNAMFORM);
     newWindow.location.href = newlocation;   <form action="/adm/coursedocs" method="post" name="subnewaboutme">
 }   <input type="hidden" name="folderpath" value="$path" />
    <input type="hidden" name="importdetail"
    value="$plainname=/adm/$udom/$uname/aboutme" />
 function finishpick() {   <span class="LC_nobreak">
     var title=this.document.forms.extimport.title.value;   <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
     var url=this.document.forms.extimport.url.value;   $help{'My Personal Info'}
     var form=this.document.forms.extimport.useform.value;   </span>
     var residx=this.document.forms.extimport.residx.value;   </form>
     eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');  SNAMFORM
 }  
      $r->print(<<ENDSUPFORM);
 function changename(folderpath,index,oldtitle,container,pagesymb) {  <ul class="LC_TabContent">
     var title=prompt('$lt{"p_chn"}',oldtitle);  <li>$lt{'nd'}</li>
     if (title) {  <li>$lt{'sd'}</li>
  this.document.forms.renameform.markcopy.value=-1;  <li>$lt{'hao'}</li>
  this.document.forms.renameform.title.value=title;  </ul>
  this.document.forms.renameform.cmd.value='rename_'+index;  <table class="LC_docs_adddocs">
         if (container == 'sequence') {  <tr><td>
     this.document.forms.renameform.folderpath.value=folderpath;  $supupdocform
         }  </td>
         if (container == 'page') {  <td>
             this.document.forms.renameform.pagepath.value=folderpath;  $supnewfolderform
             this.document.forms.renameform.pagesymb.value=pagesymb;  <br />
         }  $supnewextform
         this.document.forms.renameform.submit();  <br />
     }  $supnewsylform
 }  <br />
   $supnewaboutmeform
 function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {  </td></tr>
     if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {  </table></td></tr>
  this.document.forms.renameform.markcopy.value=-1;  ENDSUPFORM
  this.document.forms.renameform.cmd.value='del_'+index;         }
         if (container == 'sequence') {      }
             this.document.forms.renameform.folderpath.value=folderpath;      $r->print('</table>');
         }      if ($allowed) {
         if (container == 'page') {   $r->print('
             this.document.forms.renameform.pagepath.value=folderpath;  <form method="post" name="extimport" action="/adm/coursedocs">
             this.document.forms.renameform.pagesymb.value=pagesymb;    <input type="hidden" name="title" />
         }    <input type="hidden" name="url" />
         this.document.forms.renameform.submit();    <input type="hidden" name="useform" />
     }    <input type="hidden" name="residx" />
 }  </form>');
       }
 function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {    } else {
     if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {        unless ($upload_result eq 'phasetwo') {
  this.document.forms.renameform.cmd.value='cut_'+index;  # -------------------------------------------------------- This is showdoc mode
  this.document.forms.renameform.markcopy.value=index;            $r->print("<h1>".&mt('Uploaded Document').' - '.
  this.document.forms.renameform.copyfolder.value=folder+'.'+container;   &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
         if (container == 'sequence') {  &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
             this.document.forms.renameform.folderpath.value=folderpath;            &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
         }        }
         if (container == 'page') {    }
             this.document.forms.renameform.pagepath.value=folderpath;   }
             this.document.forms.renameform.pagesymb.value=pagesymb;   $r->print(&Apache::loncommon::end_page());
         }   return OK;
         this.document.forms.renameform.submit();  }
     }  
 }  
   sub editing_js {
 function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {      my ($udom,$uname) = @_;
     this.document.forms.renameform.markcopy.value=index;      my $now = time();
     this.document.forms.renameform.copyfolder.value=folder+'.'+container;      my %lt = &Apache::lonlocal::texthash(
     if (container == 'sequence') {                                            p_mnf => 'Name of New Folder',
  this.document.forms.renameform.folderpath.value=folderpath;                                            t_mnf => 'New Folder',
     }                                            p_mnp => 'Name of New Page',
     if (container == 'page') {                                            t_mnp => 'New Page',
  this.document.forms.renameform.pagepath.value=folderpath;                                            p_mxu => 'Title for the Uploaded Score',
  this.document.forms.renameform.pagesymb.value=pagesymb;                                            p_msp => 'Title for the Page',
     }                                            p_msb => 'Title for the Problem',
     this.document.forms.renameform.submit();                                            p_mdb => 'Title for the Drop Box',
 }                                            p_mbb => 'Title for the Bulletin Board',
                                             p_mab => "Enter user:domain for User's 'About Me' Page",
 ENDNEWSCRIPT                                            p_mab2 => "About [_99]",
 }                                            p_mab_alrt1 => 'Not a valid user:domain',
 1;                                            p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
 __END__                                            p_chn => 'New Title',
                                             p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
                                             p_rmr2a => 'Remove[_99]',
 =head1 NAME                                            p_rmr2b => '?[_99]',
                                             p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
 Apache::londocs.pm                                            p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
                                             p_ctr2a => 'Cut[_98]',
 =head1 SYNOPSIS                                            p_ctr2b => '?[_98]'
                                           );
 This is part of the LearningOnline Network with CAPA project  
 described at http://www.lon-capa.org.      return <<ENDNEWSCRIPT;
   function makenewfolder(targetform,folderseq) {
 =head1 SUBROUTINES      var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
       if (foldername) {
 =over         targetform.importdetail.value=escape(foldername)+"="+folderseq;
           targetform.submit();
 =item %help=()      }
   }
 Available help topics  
   function makenewpage(targetform,folderseq) {
 =item mapread()      var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
       if (pagename) {
 Mapread read maps into LONCAPA::map:: global arrays           targetform.importdetail.value=escape(pagename)+"="+folderseq;
 @order and @resources, determines status          targetform.submit();
 sets @order - pointer to resources in right order      }
 sets @resources - array with the resources with correct idx  }
   
 =item authorhosts()  function makenewext(targetname) {
       this.document.forms.extimport.useform.value=targetname;
 Return hash with valid author names      this.document.forms.extimport.title.value='';
       this.document.forms.extimport.url.value='';
 =item dumpbutton()      this.document.forms.extimport.residx.value='';
       window.open('/adm/rat/extpickframe.html');
 Generate "dump" button  }
   
 =item clean()  function edittext(targetname,residx,title,url) {
       this.document.forms.extimport.useform.value=targetname;
 =item dumpcourse()      this.document.forms.extimport.residx.value=residx;
       this.document.forms.extimport.url.value=url;
     Actually dump course      this.document.forms.extimport.title.value=title;
       window.open('/adm/rat/extpickframe.html');
   }
 =item exportbutton()  
   function makeexamupload() {
     Generate "export" button     var title=prompt('$lt{"p_mxu"}');
      if (title) {
 =item exportcourse()      this.document.forms.newexamupload.importdetail.value=
    escape(title)+'=/res/lib/templates/examupload.problem';
 =item create_ims_store()      this.document.forms.newexamupload.submit();
      }
 =item build_package()  }
   
 =item get_dependencies()  function makesmppage() {
      var title=prompt('$lt{"p_msp"}');
 =item process_content()     if (title) {
       this.document.forms.newsmppg.importdetail.value=
 =item replicate_content()   escape(title)+'=/adm/$udom/$uname/$now/smppg';
       this.document.forms.newsmppg.submit();
 =item extract_media()     }
   }
 =item store_template()  
   function makesmpproblem() {
 =item group_import()     var title=prompt('$lt{"p_msb"}');
      if (title) {
     Imports the given (name, url) resources into the course      this.document.forms.newsmpproblem.importdetail.value=
     coursenum, coursedom, and folder must precede the list   escape(title)+'=/res/lib/templates/simpleproblem.problem';
       this.document.forms.newsmpproblem.submit();
 =item breadcrumbs()     }
   }
 =item log_docs()  
   function makedropbox() {
 =item docs_change_log()     var title=prompt('$lt{"p_mdb"}');
      if (title) {
 =item update_paste_buffer()      this.document.forms.newdropbox.importdetail.value=
           escape(title)+'=/res/lib/templates/DropBox.problem';
 =item print_paste_buffer()      this.document.forms.newdropbox.submit();
      }
 =item do_paste_from_buffer()  }
   
 =item update_parameter()  function makebulboard() {
      var title=prompt('$lt{"p_mbb"}');
 =item handle_edit_cmd()     if (title) {
       this.document.forms.newbul.importdetail.value=
 =item editor()   escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
       this.document.forms.newbul.submit();
 =item process_file_upload()     }
   }
 =item process_secondary_uploads()  
   function makeabout() {
 =item is_supplemental_title()     var user=prompt("$lt{'p_mab'}");
      if (user) {
 =item parse_supplemental_title()         var comp=new Array();
          comp=user.split(':');
 =item entryline()         if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
      if ((comp[0]) && (comp[1])) {
 =item tiehash()         this.document.forms.newaboutsomeone.importdetail.value=
      '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 =item untiehash()         this.document.forms.newaboutsomeone.submit();
      } else {
 =item checkonthis()                 alert("$lt{'p_mab_alrt1'}");
              }
 check on this         } else {
              alert("$lt{'p_mab_alrt2'}");
 =item verifycontent()         }
      }
 Verify Content  }
   
 =item devalidateversioncache() & checkversions()  function makeims() {
       var caller = document.forms.ims.folder.value;
 Check Versions      var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
       newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
 =item mark_hash_old()      newWindow.location.href = newlocation;
   }
 =item is_hash_old()  
   
 =item changewarning()  function finishpick() {
       var title=this.document.forms.extimport.title.value;
 =item init_breadcrumbs()      var url=this.document.forms.extimport.url.value;
       var form=this.document.forms.extimport.useform.value;
 Breadcrumbs for special functions      var residx=this.document.forms.extimport.residx.value;
       eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
 =back  }
   
 =cut  function changename(folderpath,index,oldtitle,container,pagesymb) {
       var title=prompt('$lt{"p_chn"}',oldtitle);
       if (title) {
    this.document.forms.renameform.markcopy.value=-1;
    this.document.forms.renameform.title.value=title;
    this.document.forms.renameform.cmd.value='rename_'+index;
           if (container == 'sequence') {
       this.document.forms.renameform.folderpath.value=folderpath;
           }
           if (container == 'page') {
               this.document.forms.renameform.pagepath.value=folderpath;
               this.document.forms.renameform.pagesymb.value=pagesymb;
           }
           this.document.forms.renameform.submit();
       }
   }
   
   function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
       if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
    this.document.forms.renameform.markcopy.value=-1;
    this.document.forms.renameform.cmd.value='del_'+index;
           if (container == 'sequence') {
               this.document.forms.renameform.folderpath.value=folderpath;
           }
           if (container == 'page') {
               this.document.forms.renameform.pagepath.value=folderpath;
               this.document.forms.renameform.pagesymb.value=pagesymb;
           }
           this.document.forms.renameform.submit();
       }
   }
   
   function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
       if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
    this.document.forms.renameform.cmd.value='cut_'+index;
    this.document.forms.renameform.markcopy.value=index;
    this.document.forms.renameform.copyfolder.value=folder+'.'+container;
           if (container == 'sequence') {
               this.document.forms.renameform.folderpath.value=folderpath;
           }
           if (container == 'page') {
               this.document.forms.renameform.pagepath.value=folderpath;
               this.document.forms.renameform.pagesymb.value=pagesymb;
           }
           this.document.forms.renameform.submit();
       }
   }
   
   function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
       this.document.forms.renameform.markcopy.value=index;
       this.document.forms.renameform.copyfolder.value=folder+'.'+container;
       if (container == 'sequence') {
    this.document.forms.renameform.folderpath.value=folderpath;
       }
       if (container == 'page') {
    this.document.forms.renameform.pagepath.value=folderpath;
    this.document.forms.renameform.pagesymb.value=pagesymb;
       }
       this.document.forms.renameform.submit();
   }
   
   
   ENDNEWSCRIPT
   }
   1;
   __END__
   
   
   =head1 NAME
   
   Apache::londocs.pm
   
   =head1 SYNOPSIS
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   =head1 SUBROUTINES
   
   =over
   
   =item %help=()
   
   Available help topics
   
   =item mapread()
   
   Mapread read maps into LONCAPA::map:: global arrays
   @order and @resources, determines status
   sets @order - pointer to resources in right order
   sets @resources - array with the resources with correct idx
   
   =item authorhosts()
   
   Return hash with valid author names
   
   =item dumpbutton()
   
   Generate "dump" button
   
   =item clean()
   
   =item dumpcourse()
   
       Actually dump course
   
   
   =item exportbutton()
   
       Generate "export" button
   
   =item exportcourse()
   
   =item create_ims_store()
   
   =item build_package()
   
   =item get_dependencies()
   
   =item process_content()
   
   =item replicate_content()
   
   =item extract_media()
   
   =item store_template()
   
   =item group_import()
   
       Imports the given (name, url) resources into the course
       coursenum, coursedom, and folder must precede the list
   
   =item breadcrumbs()
   
   =item log_docs()
   
   =item docs_change_log()
   
   =item update_paste_buffer()
   
   =item print_paste_buffer()
   
   =item do_paste_from_buffer()
   
   =item update_parameter()
   
   =item handle_edit_cmd()
   
   =item editor()
   
   =item process_file_upload()
   
   =item process_secondary_uploads()
   
   =item is_supplemental_title()
   
   =item parse_supplemental_title()
   
   =item entryline()
   
   =item tiehash()
   
   =item untiehash()
   
   =item checkonthis()
   
   check on this
   
   =item verifycontent()
   
   Verify Content
   
   =item devalidateversioncache() & checkversions()
   
   Check Versions
   
   =item mark_hash_old()
   
   =item is_hash_old()
   
   =item changewarning()
   
   =item init_breadcrumbs()
   
   Breadcrumbs for special functions
   
   =back
   
   =cut

Removed from v.1.321  
changed lines
  Added in v.1.326


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>