Diff for /loncom/interface/londocs.pm between versions 1.284 and 1.327

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


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