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

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


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