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

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


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