Diff for /loncom/interface/londocs.pm between versions 1.266 and 1.328

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


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