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

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


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