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

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


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