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

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

Removed from v.1.281  
changed lines
  Added in v.1.327


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