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

version 1.326, 2009/01/28 11:51:22 version 1.481, 2012/04/08 22:34:58
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();
     }            $r->print(&Apache::loncommon::modify_html_refs('coursedoc',$destination,
             while($cols_output++ < 4) {                                                           $docuname,$docudom,undef,
                 $r->print('</font></td><td><font>')                                                           $dir_root).
             }                     &return_to_editor());
     $r->print('</font></td></tr>'."\n");        } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
  }            $uploadphase = 'decompress_phase_one';
     }            $r->print(&decompression_phase_one().
     $r->print('</table></form>');                      &return_to_editor());
     $r->print('<h1>'.&mt('Done').'.</h1>');        } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
             $uploadphase = 'decompress_phase_two';
     &untiehash();            $r->print(&decompression_phase_two().
 }                      &return_to_editor());
         }
 sub mark_hash_old {    }
     my $retie_hash=0;  
     if ($hashtied) {    unless ($showdoc || $uploadphase) {  
  $retie_hash=1;  # -----------------------------------------------------------------------------
  &untiehash();         my %lt=&Apache::lonlocal::texthash(
     }                  'uplm' => 'Upload a new main '.lc($crstype).' document',
     &tiehash('write');                  'upls' => 'Upload a new supplemental '.lc($crstype).' document',
     $hash{'old'}=1;                  'impp' => 'Import a document',
     &untiehash();   'copm' => 'All documents out of a published map into this folder',
     if ($retie_hash) { &tiehash(); }                  'upld' => 'Import Document',
 }                  'srch' => 'Search',
                   'impo' => 'Import',
 sub is_hash_old {   'wish' => 'Import from Wishlist',
     my $untie_hash=0;                  'selm' => 'Select Map',
     if (!$hashtied) {                  'load' => 'Load Map',
  $untie_hash=1;                  'reco' => 'Recover Deleted Documents',
  &tiehash();                  'newf' => 'New Folder',
     }                  'newp' => 'New Composite Page',
     my $return=$hash{'old'};                  'extr' => 'External Resource',
     if ($untie_hash) { &untiehash(); }                  'syll' => 'Syllabus',
     return $return;                  'navc' => 'Table of Contents',
 }                  'sipa' => 'Simple Course Page',
                   'sipr' => 'Simple Problem',
 sub changewarning {                  'drbx' => 'Drop Box',
     my ($r,$postexec,$message,$url)=@_;                  'scuf' => 'External Scores (handgrade, upload, clicker)',
     if (!&is_hash_old()) { return; }                  'bull' => 'Discussion Board',
     my $pathvar='folderpath';                  'mypi' => 'My Personal Information Page',
     my $path=&escape($env{'form.folderpath'});                  'grpo' => 'Group Portfolio',
     if (!defined($url)) {                  'rost' => 'Course Roster',
  if (defined($env{'form.pagepath'})) {   'abou' => 'Personal Information Page for a User',
     $pathvar='pagepath';                  'imsf' => 'IMS Import',
     $path=&escape($env{'form.pagepath'});                  'imsl' => 'Import IMS package',
     $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});                  'file' =>  'File',
  }                  'title' => 'Title',
  $url='/adm/coursedocs?'.$pathvar.'='.$path;                  'comment' => 'Comment',
     }                  'parse' => 'Upload embedded images/multimedia files if HTML file',
     my $course_type = &Apache::loncommon::course_type();   'nd' => 'Upload Document',
     if (!defined($message)) {   'pm' => 'Published Map',
  $message='Changes will become active for your current session after [_1], or the next time you log in.';   'sd' => 'Special Document',
     }   'mo' => 'More Options',
     $r->print("\n\n".    );
 '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".  # -----------------------------------------------------------------------------
 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.   my $fileupload=(<<FIUP);
 '<input type="hidden" name="orgurl" value="'.$url.   $lt{'file'}:<br />
 '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.   <input type="file" name="uploaddoc" size="40" />
 &mt($message,' <input type="hidden" name="'.  FIUP
     $env{'request.role'}.'" value="1" /><input type="button" value="'.  
     &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').   my $checkbox=(<<CHBO);
 $help{'Caching'}.'</span></h3></form>'."\n\n");   <!-- <label>$lt{'parse'}?
 }   <input type="checkbox" name="parserflag" />
    </label> -->
    <label>
 sub init_breadcrumbs {   <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
     my ($form,$text)=@_;   </label>
     &Apache::lonhtmlcommon::clear_breadcrumbs();  CHBO
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",  
     text=>"Edit ".&Apache::loncommon::course_type(),      my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
     faq=>273,   my $fileuploadform=(<<FUFORM);
     bug=>'Instructor Interface',   <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
                                             help => 'Docs_Adding_Course_Doc'});   <input type="hidden" name="active" value="aa" />
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',   $fileupload
     text=>$text,   <br />
     faq=>273,   $lt{'title'}:<br />
     bug=>'Instructor Interface'});   <input type="text" size="60" name="comment" />
 }   $uploadtag
    <input type="hidden" name="cmd" value="upload_default" />
    <br />
    <span class="LC_nobreak" style="float:left">
    $checkbox
 sub handler {   </span>
     my $r = shift;  FUFORM
     &Apache::loncommon::content_type($r,'text/html');      $fileuploadform .= $fileuploada.'</form>';
     $r->send_http_header;  
     return OK if $r->header_only;   my $simpleeditdefaultform=(<<SEDFFORM);
     my $type = &Apache::loncommon::course_type();   <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
    <input type="hidden" name="active" value="bb" />
   SEDFFORM
 # --------------------------------------------- Initialize help topics for this   my @simpleeditdefaultforma = ( 
     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',   { '<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_External_Resource','Navigate_Content',   { '<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'}" },
                'Adding_Folders','Docs_Overview', 'Load_Map',   { '<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>" },
                'Supplemental','Score_Upload_Form','Adding_Pages',   );
                'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',   $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
                'Check_Resource_Versions','Verify_Content') {   $simpleeditdefaultform .=(<<SEDFFORM);
  $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);   <hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
     }   $lt{'copm'}<br />
     # Composite help files   <input type="text" size="40" name="importmap" /><br />
     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(   <span class="LC_nobreak" style="float:left"><input type="button"
     'Docs_About_Syllabus,Docs_Editing_Templated_Pages');   onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(   value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
     'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');   $help{'Load_Map'}</span>
     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(   </form>
     'Option_Response_Simple');  SEDFFORM
     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(  
     'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');        my $extresourcesform=(<<ERFORM);
     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(        <form action="/adm/coursedocs" method="post" name="newext">
   'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');        $uploadtag
     $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');        <input type="hidden" name="importdetail" value="" />
     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');        <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
         </form>
 # does this user have privileges to modify docs  ERFORM
     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});  
   if ($allowed && $env{'form.verify'}) {  
       &init_breadcrumbs('verify','Verify Content');      if ($allowed) {
       &verifycontent($r);   &update_paste_buffer($coursenum,$coursedom);
   } elsif ($allowed && $env{'form.listsymbs'}) {         my %lt=&Apache::lonlocal::texthash(
       &init_breadcrumbs('listsymbs','List Symbs');   'vc' => 'Verify Content',
       &list_symbs($r);   'cv' => 'Check/Set Resource Versions',
   } elsif ($allowed && $env{'form.docslog'}) {   'ls' => 'List Symbs',
       &init_breadcrumbs('docslog','Show Log');                                           'sl' => 'Show Log'
       &docs_change_log($r);    );
   } elsif ($allowed && $env{'form.versions'}) {  
       &init_breadcrumbs('versions','Check/Set Resource Versions');   $r->print(<<HIDDENFORM);
       &checkversions($r);   <form name="renameform" method="post" action="/adm/coursedocs">
   } elsif ($allowed && $env{'form.dumpcourse'}) {     <input type="hidden" name="title" />
       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');     <input type="hidden" name="cmd" />
       &dumpcourse($r);     <input type="hidden" name="markcopy" />
   } elsif ($allowed && $env{'form.exportcourse'}) {     <input type="hidden" name="copyfolder" />
       &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');     $containertag
       &exportcourse($r);   </form>
   } else {   <form name="simpleedit" method="post" action="/adm/coursedocs">
 # is this a standard course?     <input type="hidden" name="importdetail" value="" />
      $uploadtag
     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);   </form>
     my $forcestandard = 0;  HIDDENFORM
     my $forcesupplement;      }
     my $script='';  
     my $showdoc=0;  # Generate the tabs
     my $containertag;      my $mode;
     my $uploadtag;      if (($supplementalflag) && (!$allowed)) {
           &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
       } else {
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},          &startContentScreen($r,($supplementalflag?'suppdocs':'docs'));
     ['folderpath','pagepath',      }
      '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',      my $savefolderpath;
                                               {'folderpath' => 'scalar'});  
     }      if ($allowed) {
     if (!$env{'form.folderpath'}) {         my $folder=$env{'form.folder'};
         &Apache::loncommon::restore_course_settings('docs_folderpath',         if ($folder eq '' || $supplementalflag) {
                                               {'pagepath' => 'scalar'});             $folder='default';
     }     $savefolderpath = $env{'form.folderpath'};
     if ($env{'form.pagepath'}) {     $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
        $env{'form.folderpath'}='';             $uploadtag = '<input type="hidden" name="folderpath" value="'.
     }         &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {         }
         $env{'form.folderpath'} = 'supplemental&'.         my $postexec='';
                                   &escape(&mt('Supplemental '.$type.' Documents')).'&'.         if ($folder eq 'default') {
                                   $env{'form.folderpath'};             $r->print('<script type="text/javascript">'."\n"
     }                      .'// <![CDATA['."\n"
     &Apache::loncommon::store_course_settings('docs_folderpath',                      .'this.window.name="loncapaclient";'."\n"
                                                 {'pagepath' => 'scalar',                      .'// ]]>'."\n"
                                                  'folderpath' => 'scalar'});                      .'</script>'."\n"
     if ($env{'form.folderpath'}) {         );
  my (@folderpath)=split('&',$env{'form.folderpath'});         } else {
  $env{'form.foldername'}=&unescape(pop(@folderpath));             #$postexec='self.close();';
  $env{'form.folder'}=pop(@folderpath);         }
     }         my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
     if ($env{'form.pagepath'}) {                       '.sequence';
         my (@pagepath)=split('&',$env{'form.pagepath'});         my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
         $env{'form.pagename'}=&unescape(pop(@pagepath));                       '.page';
         $env{'form.folder'}=pop(@pagepath);   my $container='sequence';
         $containertag = '<input type="hidden" name="pagepath" value="" />'.   if ($env{'form.pagepath'}) {
     '<input type="hidden" name="pagesymb" value="" />';      $container='page';
         $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.   }
     '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';   my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
     }  
     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {  
        $showdoc='/'.$1;  
     }   my $recoverform=(<<RFORM);
     unless ($showdoc) { # got called from remote   <form action="/adm/groupsort" method="post" name="recover">
        if (($env{'form.folder'}=~/^(?:group|default)_/) ||   <a class="LC_menubuttons_link" href="javascript:groupopen('$readfile',1)">$lt{'reco'}</a>
           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {   </form>
            $forcestandard = 1;  RFORM
        }  
        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);   my $imspform=(<<IMSPFORM);
    <form action="/adm/imsimportdocs" method="post" name="ims">
        if ($allowed) {   <input type="hidden" name="folder" value="$folder" />
          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);   <a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
          $script=&Apache::lonratedt::editscript('simple');   </form>
        }  IMSPFORM
     } else { # got called in sequence from course  
        $allowed=0;   my $newnavform=(<<NNFORM);
     }   <form action="/adm/coursedocs" method="post" name="newnav">
    <input type="hidden" name="active" value="cc" />
 # get course data   $uploadtag
     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};   <input type="hidden" name="importdetail" 
     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};   value="$lt{'navc'}=/adm/navmaps" />
    <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
 # get personal data   $help{'Navigate_Content'}
     my $uname=$env{'user.name'};   </form>
     my $udom=$env{'user.domain'};  NNFORM
     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));   my $newsmppageform=(<<NSPFORM);
    <form action="/adm/coursedocs" method="post" name="newsmppg">
 # graphics settings   <input type="hidden" name="active" value="cc" />
    $uploadtag
     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");   <input type="hidden" name="importdetail" value="" />
    <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
     if ($allowed) {   $help{'Simple Page'}
  $script .= &editing_js($udom,$uname);   </form>
     }  NSPFORM
 # -------------------------------------------------------------------- Body tag  
     $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';   my $newsmpproblemform=(<<NSPROBFORM);
     my $brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}];   <form action="/adm/coursedocs" method="post" name="newsmpproblem">
     $r->print(&Apache::loncommon::start_page("$type Documents", $script,   <input type="hidden" name="active" value="cc" />
     {'force_register' => $showdoc,   $uploadtag
                                      'bread_crumbs' => $brcrum}).   <input type="hidden" name="importdetail" value="" />
       &Apache::loncommon::help_open_menu('','',273,'RAT'));   <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
     $help{'Simple Problem'}
   my %allfiles = ();   </form>
   my %codebase = ();  
   my ($upload_result,$upload_output);  NSPROBFORM
   if ($allowed) {  
       if (($env{'form.uploaddoc.filename'}) &&   my $newdropboxform=(<<NDBFORM);
   ($env{'form.cmd'}=~/^upload_(\w+)/)) {   <form action="/adm/coursedocs" method="post" name="newdropbox">
 # Process file upload - phase one - upload and parse primary file.     <input type="hidden" name="active" value="cc" />
   undef($hadchanges);   $uploadtag
           $upload_result = &process_file_upload(\$upload_output,$coursenum,   <input type="hidden" name="importdetail" value="" />
  $coursedom,\%allfiles,   <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
  \%codebase,$1);   </form>
   if ($hadchanges) {  NDBFORM
       &mark_hash_old();  
   }   my $newexuploadform=(<<NEXUFORM);
           if ($upload_result eq 'phasetwo') {   <form action="/adm/coursedocs" method="post" name="newexamupload">
               $r->print($upload_output);   <input type="hidden" name="active" value="cc" />
           }   $uploadtag
       } elsif ($env{'form.phasetwo'}) {   <input type="hidden" name="importdetail" value="" />
           my %newname = ();   <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
           my %origname = ();   $help{'Score_Upload_Form'}
           my %attribs = ();   </form>
           my $updateflag = 0;  NEXUFORM
           my $residx = $env{'form.newidx'};  
           my $primary_url = &unescape($env{'form.primaryurl'});   my $newbulform=(<<NBFORM);
 # Process file upload - phase two - gather secondary files.   <form action="/adm/coursedocs" method="post" name="newbul">
           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {   <input type="hidden" name="active" value="cc" />
               if ($env{'form.embedded_item_'.$i.'.filename'}) {   $uploadtag
                   my $javacodebase;   <input type="hidden" name="importdetail" value="" />
                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);   <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});   $help{'Bulletin Board'}
                   if (exists($env{'form.embedded_codebase_'.$i})) {   </form>
                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});    NBFORM
                       $origname{$i} =~ s#^\Q$javacodebase\E/##;  
                   }   my $newaboutmeform=(<<NAMFORM);
                   my @attributes = ();   <form action="/adm/coursedocs" method="post" name="newaboutme">
                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {   <input type="hidden" name="active" value="cc" />
                       @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});   $uploadtag
                   } else {   <input type="hidden" name="importdetail" 
                       @attributes = ($env{'form.embedded_attrib_'.$i});   value="$plainname=/adm/$udom/$uname/aboutme" />
                   }   <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
                   foreach my $attr (@attributes) {   $help{'My Personal Information Page'}
                       push(@{$attribs{$i}},&unescape($attr));   </form>
                   }  NAMFORM
                   if ($javacodebase) {  
                       $codebase{$i} = $javacodebase;   my $newaboutsomeoneform=(<<NASOFORM);
                       $codebase{$i} =~ s#/$##;   <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
                       $updateflag = 1;   <input type="hidden" name="active" value="cc" />
                   }   $uploadtag
               }   <input type="hidden" name="importdetail" value="" />
               unless ($newname{$i} eq $origname{$i}) {   <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
                   $updateflag = 1;   </form>
               }  NASOFORM
           }  
 # Process file upload - phase three - modify primary file  
           if ($updateflag) {   my $newrosterform=(<<NROSTFORM);
               my ($content,$rtncode);   <form action="/adm/coursedocs" method="post" name="newroster">
               my $updateflag = 0;   <input type="hidden" name="active" value="cc" />
               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);   $uploadtag
               if ($getstatus eq 'ok') {   <input type="hidden" name="importdetail" 
                   foreach my $item (keys(%newname)) {   value="$lt{'rost'}=/adm/viewclasslist" />
                       if ($newname{$item} ne $origname{$item}) {   <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
                           my $attrib_regexp = '';   $help{'Course Roster'}
                           if (@{$attribs{$item}} > 1) {   </form>
                               $attrib_regexp = join('|',@{$attribs{$item}});  NROSTFORM
                           } else {  
                               $attrib_regexp = $attribs{$item}[0];  my $specialdocumentsform;
                           }  my @specialdocumentsforma;
                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {  my $gradingform;
                           }  my @gradingforma;
                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;  my $communityform;
                       }  my @communityforma;
                       if (exists($codebase{$item})) {  my $newfolderform;
                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs  my $newfolderb;
                       }  
                   }   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 # Save edited file.  
                   my $saveresult;   my $newpageform=(<<NPFORM);
                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};   <form action="/adm/coursedocs" method="post" name="newpage">
                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};   <input type="hidden" name="folderpath" value="$path" />
                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);   <input type="hidden" name="importdetail" value="" />
               } else {   <input type="hidden" name="active" value="cc" />
                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);   <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);
 # -----------------------------------------------------------------------------   <form action="/adm/coursedocs" method="post" name="newfolder">
        my %lt=&Apache::lonlocal::texthash(   <input type="hidden" name="folderpath" value="$path" />
                 'uplm' => 'Upload a new main '.lc($type).' document',   <input type="hidden" name="importdetail" value="" />
                 'upls' => 'Upload a new supplemental '.lc($type).' document',   <input type="hidden" name="active" value="aa" />
                 'impp' => 'Import a document',   <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
                 'pubd' => 'Published Documents',   </form>
  'copm' => 'All documents out of a published map into this folder',  NFFORM
                 'upld' => 'Upload Document',  
                 'srch' => 'Search',   my $newsylform=(<<NSYLFORM);
                 'impo' => 'Import',   <form action="/adm/coursedocs" method="post" name="newsyl">
  'book' => 'Import Bookmarks',   <input type="hidden" name="active" value="cc" />
                 'selm' => 'Select Map',   $uploadtag
                 'load' => 'Load Map',   <input type="hidden" name="importdetail" 
                 'reco' => 'Recover Deleted Resources',   value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
                 'newf' => 'New Folder',   <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
                 'newp' => 'New Composite Page',   $help{'Syllabus'}
                 'extr' => 'External Resource',  
                 'syll' => 'Syllabus',   </form>
                 'navc' => 'Navigate Contents',  NSYLFORM
                 'sipa' => 'Simple Page',  
                 'sipr' => 'Simple Problem',   my $newgroupfileform=(<<NGFFORM);
                 'drbx' => 'Drop Box',   <form action="/adm/coursedocs" method="post" name="newgroupfiles">
                 'scuf' => 'Score Upload Form',   <input type="hidden" name="active" value="cc" />
                 'bull' => 'Bulletin Board',   $uploadtag
                 'mypi' => 'My Personal Info',   <input type="hidden" name="importdetail"
                 'grpo' => 'Group Files',   value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
                 'rost' => 'Course Roster',   <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
  'abou' => 'About User',   $help{'Group Portfolio'}
                 'imsf' => 'Import IMS package',   </form>
                 'file' =>  'File',  NGFFORM
                 'title' => 'Title',   @specialdocumentsforma=(
                 'comment' => 'Comment',   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
                 'parse' => 'Upload embedded images/multimedia files if HTML file!',   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
  'nd' => 'New Document',   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
  'pm' => 'Published Map',          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
  'sd' => 'Special Document',          );
  'mo' => 'More Options',          $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
  'hao' => 'Hide all Options'  
   );  
 # -----------------------------------------------------------------------------          my @importdoc = (
  my $fileupload=(<<FIUP);          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
  $lt{'file'}:<br />          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
  <input type="file" name="uploaddoc" size="40" />          $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
 FIUP  
           @gradingforma=(
  my $checkbox=(<<CHBO);          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
  <!-- <label>$lt{'parse'}?          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
  <input type="checkbox" name="parserflag" />          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
  </label> -->  
  <label>          );
  <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}          $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
  </label>  
 CHBO          @communityforma=(
          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
  my $fileuploadform=(<<FUFORM);          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
  <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
  $fileupload          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
  <br />          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
  $lt{'title'}:<br />          );
  <input type="text" size="50" name="comment" />          $communityform = &create_form_ul(&create_list_elements(@communityforma));
  $uploadtag  
  <input type="hidden" name="cmd" value="upload_default" />  
  <br />  
  <span class="LC_nobreak">  my @tools = (
  $checkbox  # {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" />'=>$extresourcesform},
  </span>  # {'<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},
  <br />   );
  <span class="LC_nobreak">  
  <input type="submit" value="$lt{'upld'}" />  my %orderhash = (
  $help{'Uploading_From_Harddrive'}                  'aa' => ['Import Documents',$fileuploadform],
  </span>                  'bb' => ['Published Resources',$simpleeditdefaultform],
  </form>                  'cc' => ['Grading Resources',$gradingform],
 FUFORM   'ff' => ['Tools', &create_form_ul(&create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
                   );
  my $simpleeditdefaultform=(<<SEDFFORM);  unless ($env{'form.pagepath'}) {
  <form action="/adm/coursedocs" method="post" name="simpleeditdefault">      $orderhash{'00'} = ['Newfolder',$newfolderform];
  $lt{'pubd'}<br />      $orderhash{'dd'} = ['Community Resources',$communityform];
  $uploadtag      $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
  <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />  }
  <br />  
  <span class="LC_nobreak">   $hadchanges=0;
  <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />         unless ($supplementalflag) {
  $help{'Importing_LON-CAPA_Resource'}            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
  </span>                                $supplementalflag,\%orderhash,$iconpath);
  <br />            if ($error) {
  <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
  <hr />            }
  <p>            if ($hadchanges) {
  $lt{'copm'}<br />               &mark_hash_old();
  <input type="text" size="40" name="importmap" /><br />            }
  <span class="LC_nobreak"><input type="button"  
  onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"            &changewarning($r,'');
  value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />          }
  $help{'Load_Map'}</span>      }
  </p>  
  </form>  # Supplemental documents start here
 SEDFFORM  
          my $folder=$env{'form.folder'};
  my $extresourcesform=(<<ERFORM);         unless ($supplementalflag) {
  <form action="/adm/coursedocs" method="post" name="newext">     $folder='supplemental';
  $uploadtag         }
  <input type="hidden" name="importdetail" value="" />         if ($folder =~ /^supplemental$/ &&
  <span class="LC_nobreak">     (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
  <input name="newext" type="button" onClick="javascript:makenewext('newext');"            $env{'form.folderpath'} = &supplemental_base();
  value="$lt{'extr'}" /> $help{'Adding_External_Resource'}         } elsif ($allowed) {
  </span>    $env{'form.folderpath'} = $savefolderpath;
  </form>         }
 ERFORM         $env{'form.pagepath'} = '';
          if ($allowed) {
     if ($allowed) {     my $folderseq=
  &update_paste_buffer($coursenum,$coursedom);         '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
        my $dumpbut=&dumpbutton();         '.sequence';
        my $exportbut=&exportbutton();  
        my %lt=&Apache::lonlocal::texthash(     my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
  'vc' => 'Verify Content',  
  'cv' => 'Check/Set Resource Versions',   my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
  'ls' => 'List Symbs',   my $supupdocform=(<<SUPDOCFORM);
                                          'sl' => 'Show Log'   <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
   );   <input type="hidden" name="active" value="ee" />
    $fileupload
        my $folderpath=$env{'form.folderpath'};   <br />
        if (!$folderpath) {   <br />
    if ($env{'form.folder'} eq '' ||   <span class="LC_nobreak">
        $env{'form.folder'} eq 'supplemental') {   $checkbox
        $folderpath='default&'.   </span>
    &escape(&mt('Main '.$type.' Documents'));   <br /><br />
    }   $lt{'comment'}:<br />
        }   <textarea cols="50" rows="4" name="comment"></textarea>
        unless ($env{'form.pagepath'}) {   <br />
            $containertag = '<input type="hidden" name="folderpath" value="" />';   <input type="hidden" name="folderpath" value="$path" />
            $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';   <input type="hidden" name="cmd" value="upload_supplemental" />
        }  SUPDOCFORM
    $supupdocform .=  &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
        $r->print(<<ENDCOURSEVERIFY);  
 <form name="renameform" method="post" action="/adm/coursedocs">   my $supnewfolderform=(<<SNFFORM);
   <input type="hidden" name="title" />   <form action="/adm/coursedocs" method="post" name="supnewfolder">
   <input type="hidden" name="cmd" />   <input type="hidden" name="active" value="ee" />
   <input type="hidden" name="markcopy" />   <input type="hidden" name="folderpath" value="$path" />
   <input type="hidden" name="copyfolder" />   <input type="hidden" name="importdetail" value="" />
   $containertag   <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
 </form>   $help{'Adding_Folders'}
 <form name="simpleedit" method="post" action="/adm/coursedocs">   </form>
   <input type="hidden" name="importdetail" value="" />  SNFFORM
   $uploadtag  
 </form>  
 <form action="/adm/coursedocs" method="post" name="courseverify">   my $supnewextform=(<<SNEFORM);
   <div class="LC_docs_course_commands">   <form action="/adm/coursedocs" method="post" name="supnewext">
    <input type="hidden" name="active" value="ff" />
       <div>   <input type="hidden" name="folderpath" value="$path" />
         <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}   <input type="hidden" name="importdetail" value="" />
       </div>   <a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
       <div>   </form>
         <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}  SNEFORM
       </div>  
         $dumpbut   my $supnewsylform=(<<SNSFORM);
         $exportbut   <form action="/adm/coursedocs" method="post" name="supnewsyl">
       <div>   <input type="hidden" name="active" value="ff" />
         <input type="submit" name="listsymbs" value="$lt{'ls'}" />   <input type="hidden" name="folderpath" value="$path" />
       </div>   <input type="hidden" name="importdetail" 
       <div>   value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
         <input type="hidden" name="folder" value="$env{'form.folder'}" />   <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
         <input type="submit" name="docslog" value="$lt{'sl'}" />   $help{'Syllabus'}
       </div>   </form>
   </div>  SNSFORM
 </form>  
 <div style="clear: both; height: 0px;">&nbsp;</div>   my $supnewaboutmeform=(<<SNAMFORM);
 ENDCOURSEVERIFY   <form action="/adm/coursedocs" method="post" name="supnewaboutme">
        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',   <input type="hidden" name="active" value="ff" />
      &mt('Editing the Table of Contents for your '.$type)));   <input type="hidden" name="folderpath" value="$path" />
     }   <input type="hidden" name="importdetail" 
 # --------------------------------------------------------- Standard documents   value="$plainname=/adm/$udom/$uname/aboutme" />
     $r->print('<table class="LC_docs_documents">');   <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
    $help{'My Personal Information Page'}
     if (($standard) && ($allowed) && (!$forcesupplement)) {   </form>
  $r->print('<tr><td class="LC_docs_document">');  SNAMFORM
 #  '<h2>'.&mt('Main Course Documents').  
 #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');  
        my $folder=$env{'form.folder'};  my @specialdocs = (
        if ($folder eq '' || $folder eq 'supplemental') {   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
            $folder='default';              =>$supnewsylform},
    $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
            $uploadtag = '<input type="hidden" name="folderpath" value="'.              =>$supnewaboutmeform},
        &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';   );
        }  my @supimportdoc = (
        my $postexec='';   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
        if ($folder eq 'default') {              =>$supnewextform},
    $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');          );
        } else {  $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
            #$postexec='self.close();';  my %suporderhash = (
        }   '00' => ['Supnewfolder', $supnewfolderform],
        $hadchanges=0;                  'ee' => ['Import Documents',$supupdocform],
        my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,                  'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
    $upload_output,$type);                  );
        if ($error) {          if ($supplementalflag) {
    $r->print('<p><span class="LC_error">'.$error.'</span></p>');             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
        }                                 $supplementalflag,\%suporderhash,$iconpath);
        if ($hadchanges) {             if ($error) {
    &mark_hash_old();                $r->print('<p><span class="LC_error">'.$error.'</span></p>');
        }             }
        &changewarning($r,$postexec);          }
        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.      } elsif ($supplementalflag) {
                      '.sequence';          my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.                              $supplementalflag,'',$iconpath);
                      '.page';          if ($error) {
  my $container='sequence';              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
  if ($env{'form.pagepath'}) {          }
     $container='page';      }
  }  
  my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;      &endContentScreen($r);
   
       if ($allowed) {
    $r->print('
  my $recoverform=(<<RFORM);  <form method="post" name="extimport" action="/adm/coursedocs">
  <form action="/adm/groupsort" method="post" name="recover">    <input type="hidden" name="title" />
  <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />    <input type="hidden" name="url" />
  </form>    <input type="hidden" name="useform" />
 RFORM    <input type="hidden" name="residx" />
   </form>');
  my $imspform=(<<IMSPFORM);      }
  <form action="/adm/imsimportdocs" method="post" name="ims">    } else {
  <input type="hidden" name="folder" value="$folder" />        unless ($uploadphase) {
  <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />  # -------------------------------------------------------- This is showdoc mode
  </form>            $r->print("<h1>".&mt('Uploaded Document').' - '.
 IMSPFORM   &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>".
  my $newnavform=(<<NNFORM);            &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
  <form action="/adm/coursedocs" method="post" name="newnav">        }
  $uploadtag    }
  <input type="hidden" name="importdetail"   }
  value="$lt{'navc'}=/adm/navmaps" />   $r->print(&Apache::loncommon::end_page());
  <span class="LC_nobreak">   return OK;
  <input name="newnav" type="submit" value="$lt{'navc'}" />  }
  $help{'Navigate_Content'}  
  </span>  sub embedded_form_elems {
  </form>      my ($phase,$primaryurl,$newidx) = @_;
 NNFORM      my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
  my $newsmppageform=(<<NSPFORM);      return <<STATE;
  <form action="/adm/coursedocs" method="post" name="newsmppg">      <input type="hidden" name="folderpath" value="$folderpath" />
  $uploadtag      <input type="hidden" name="cmd" value="upload_embedded" />
  <input type="hidden" name="importdetail" value="" />      <input type="hidden" name="newidx" value="$newidx" />
  <span class="LC_nobreak">      <input type="hidden" name="phase" value="$phase" />
  <input name="newsmppg" type="button" value="$lt{'sipa'}"      <input type="hidden" name="primaryurl" value="$primaryurl" />
  onClick="javascript:makesmppage();" /> $help{'Simple Page'}  STATE
  </span>  }
  </form>  
 NSPFORM  sub embedded_destination {
       my $folder=$env{'form.folder'};
  my $newsmpproblemform=(<<NSPROBFORM);      my $destination = 'docs/';
  <form action="/adm/coursedocs" method="post" name="newsmpproblem">      if ($folder =~ /^supplemental/) {
  $uploadtag          $destination = 'supplemental/';
  <input type="hidden" name="importdetail" value="" />      }
  <span class="LC_nobreak">      if (($folder eq 'default') || ($folder eq 'supplemental')) {
  <input name="newsmpproblem" type="button" value="$lt{'sipr'}"          $destination .= 'default/';
  onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}      } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
  </span>          $destination .=  $2.'/';
  </form>      }
       $destination .= $env{'form.newidx'};
 NSPROBFORM      my $dir_root = '/userfiles';
       return ($destination,$dir_root);
  my $newdropboxform=(<<NDBFORM);  }
  <form action="/adm/coursedocs" method="post" name="newdropbox">  
  $uploadtag        sub return_to_editor {
  <input type="hidden" name="importdetail" value="" />      my $actionurl = '/adm/coursedocs';
  <span class="LC_nobreak">                return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
  <input name="newdropbox" type="button" value="$lt{'drbx'}"             '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
  onClick="javascript:makedropbox();" />             '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
  </span>                     '</a></p>';
  </form>  }
 NDBFORM  
   sub decompression_info {
  my $newexuploadform=(<<NEXUFORM);      my ($destination,$dir_root) = &embedded_destination();
  <form action="/adm/coursedocs" method="post" name="newexamupload">      my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  $uploadtag      my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  <input type="hidden" name="importdetail" value="" />      my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
  <span class="LC_nobreak">      my $container='sequence';
  <input name="newexamupload" type="button" value="$lt{'scuf'}"      my ($pathitem,$hiddenelem);
  onClick="javascript:makeexamupload();" />      my @hiddens = ('newidx','comment','position');
  $help{'Score_Upload_Form'}      if ($env{'form.pagepath'}) {
  </span>          $container='page';
  </form>          $pathitem = 'pagepath';
 NEXUFORM      } else {
           $pathitem = 'folderpath';
  my $newbulform=(<<NBFORM);      }
  <form action="/adm/coursedocs" method="post" name="newbul">      unshift(@hiddens,$pathitem);
  $uploadtag      foreach my $item (@hiddens) {
  <input type="hidden" name="importdetail" value="" />          if ($env{'form.'.$item}) {
  <span class="LC_nobreak">              $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
  <input name="newbulletin" type="button" value="$lt{'bull'}"                             $env{'form.'.$item}.'" />'."\n";
  onClick="javascript:makebulboard();" />          }
  $help{'Bulletin Board'}      }
  </span>      return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
  </form>              $hiddenelem);
 NBFORM  }
   
  my $newaboutmeform=(<<NAMFORM);  sub decompression_phase_one {
  <form action="/adm/coursedocs" method="post" name="newaboutme">      my ($dir,$file,$warning,$error,$output);
  $uploadtag      my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
  <input type="hidden" name="importdetail"          &decompression_info();
  value="$plainname=/adm/$udom/$uname/aboutme" />      if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
  <span class="LC_nobreak">          $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
  <input name="newaboutme" type="submit" value="$lt{'mypi'}" />      } else {
  $help{'My Personal Info'}          my $file = $1;
  </span>          $output = 
  </form>              &Apache::loncommon::process_decompression($docudom,$docuname,$file,
 NAMFORM                                                        $destination,$dir_root,
                                                         $hiddenelem);
  my $newaboutsomeoneform=(<<NASOFORM);          if ($env{'form.autoextract_camtasia'}) {
  <form action="/adm/coursedocs" method="post" name="newaboutsomeone">              $output .= &remove_archive($docudom,$docuname,$container);
  $uploadtag          }
  <input type="hidden" name="importdetail" value="" />      }
  <span class="LC_nobreak">      if ($error) {
  <input name="newaboutsomeone" type="button" value="$lt{'abou'}"          $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
  onClick="javascript:makeabout();" />                     $error.'</p>'."\n";
  </span>      }
  </form>      if ($warning) {
 NASOFORM          $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
       }
       return $output;
  my $newrosterform=(<<NROSTFORM);  }
  <form action="/adm/coursedocs" method="post" name="newroster">  
  $uploadtag  sub decompression_phase_two {
  <input type="hidden" name="importdetail"      my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
  value="$lt{'rost'}=/adm/viewclasslist" />          &decompression_info();
  <span class="LC_nobreak">      my $output;
  <input name="newroster" type="submit" value="$lt{'rost'}" />      if ($env{'form.archivedelete'}) {
  $help{'Course Roster'}          $output = &remove_archive($docudom,$docuname,$container);
  </span>      }
  </form>      $output .= 
 NROSTFORM          &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
                                                       $destination,$dir_root,$hiddenelem);
        $r->print(<<ENDFORM);      return $output;
   }
 <ul class="LC_TabContent">  
 <li>$lt{'nd'}</li>  sub remove_archive {
 <li>$lt{'pm'}</li>      my ($docudom,$docuname,$container) = @_;
 <li>$lt{'pubd'}</li>      my $map = $env{'form.folder'}.'.'.$container;
 <li>$lt{'sd'}</li>      my ($output,$delwarning,$delresult,$url);
 <li>$lt{'mo'}</li>      my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
 <li>$lt{'hao'}</li>      if ($fatal) {
 </ul>          if ($container eq 'page') {
               $delwarning = &mt('An error occurred retrieving the contents of the current page.');
 <table class="LC_docs_adddocs">          } else {
 <!-- <tr>              $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
 <th>$lt{'uplm'}</th>          }
 <th>$lt{'impp'}</th>          $delwarning .= &mt('As a result the archive file has not been removed.');
 <th>$lt{'spec'}</th>      } else {
 </tr> -->          my $currcmd = $env{'form.cmd'};
 <tr>          my $position = $env{'form.position'};
 <td>          if ($position > 0) { 
 $fileuploadform              $env{'form.cmd'} = 'del_'.$position;
 </td>              my ($title,$url,@rrest) = 
 <td>                  split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
 $simpleeditdefaultform              if (&handle_edit_cmd($docuname,$docudom)) {
 <hr />                  ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
 $recoverform                  if ($fatal) {
 ENDFORM                      if ($container eq 'page') {
        unless ($env{'form.pagepath'}) {                          $delwarning = &mt('An error occurred updating the contents of the current page.');
    $r->print(<<ENDFORM);                      } else {
 <hr />                          $delwarning = &mt('An error occurred updating the contents of the current folder.');
 $extresourcesform                      }
  <br />                  } else {
 $imspform                      $delresult = &mt('Archive file removed.');
 ENDFORM                  }
        }              }
        $r->print('</td><td>');          }
        unless ($env{'form.pagepath'}) {          $env{'form.cmd'} = $currcmd;
    my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');      }
       if ($delwarning) {
           $output = '<p class="LC_warning">'.
                      $delwarning.
  my $newpageform=(<<NPFORM);                     '</p>';
  <form action="/adm/coursedocs" method="post" name="newpage">      }
  <input type="hidden" name="folderpath" value="$path" />      if ($delresult) {
  <input type="hidden" name="importdetail" value="" />          $output .= '<p class="LC_info">'.
  <span class="LC_nobreak">                     $delresult.
  <input name="newpage" type="button"                     '</p>';
  onClick="javascript:makenewpage(this.form,'$pageseq');"      }
  value="$lt{'newp'}" />$help{'Adding_Pages'}      return $output;
  </span>  }
  </form>  
 NPFORM  sub generate_admin_options {
     my ($help_ref,$env_ref) = @_;
  my $newfolderform=(<<NFFORM);    my %lt=&Apache::lonlocal::texthash(
  <form action="/adm/coursedocs" method="post" name="newfolder">                                           'vc' => 'Verify Content',
  <input type="hidden" name="folderpath" value="$path" />                                           'cv' => 'Check/Set Resource Versions',
  <input type="hidden" name="importdetail" value="" />                                           'ls' => 'List Symbs',
  <span class="LC_nobreak">                                           'sl' => 'Show Log',
  <input name="newfolder" type="button"                                           'imse' => 'IMS Export',
  onClick="javascript:makenewfolder(this.form,'$folderseq');"                                           'dcd' => 'Dump Course Documents to Construction Space: available on other servers'
  value="$lt{'newf'}" />$help{'Adding_Folders'}                                            );
  </span>    my %help = %{$help_ref};
  </form>    my %env = %{$env_ref};
 NFFORM    my $dumpbut=&dumpbutton();
     my $exportbut=&exportbutton();
  my $newsylform=(<<NSYLFORM);    my @list = (
  <form action="/adm/coursedocs" method="post" name="newsyl">   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/verify.png" alt="'.$lt{vc}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "verify", "'.$lt{'vc'}.'")\' />' 
  $uploadtag          => "<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
  <input type="hidden" name="importdetail"   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/resversion.png" alt="'.$lt{cv}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "versions", "'.$lt{'cv'}.'")\' />'
  value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />          =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
  <span class="LC_nobreak">   );
  <input name="newsyl" type="submit" value="$lt{'syll'}" />    if($dumpbut ne ''){
  $help{'Syllabus'}    push @list, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dump.png" alt="'.$lt{dcd}.'" />'=>$dumpbut};
  </span>    }
  </form>    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').'\');" />'
 NSYLFORM            =>$exportbut},
    {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/symbs.png" alt="'.$lt{ls}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "listsymbs", "'.$lt{'ls'}.'")\'  />'
  my $newgroupfileform=(<<NGFFORM);          =>"<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'}' />"},
  <form action="/adm/coursedocs" method="post" name="newgroupfiles">   {'<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'}.'")\'  />'
  $uploadtag          =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
  <input type="hidden" name="importdetail"   );
  value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />    return '<form action="/adm/coursedocs" method="post" name="courseverify"><input type="hidden" id="dummy" />'.&create_form_ul(&create_list_elements(@list)).'</form>';
  <span class="LC_nobreak">  
  <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />  }
  $help{'Group Files'}  
  </span>  
  </form>  sub generate_edit_table {
 NGFFORM      my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto) = @_;
       return unless(ref($orderhash_ref) eq 'HASH');
       my %orderhash = %{$orderhash_ref};
            $r->print(<<ENDFORM);      my $form;
 <br />      my $activetab;
 $newfolderform      my $active;
 <br />      if($env{'form.active'} ne ''){
 $newpageform          $activetab = $env{'form.active'};
 <br />      }
 $newsylform      my $backicon = $iconpath.'clickhere.gif';
 <br />      my $backtext = &mt('To Overview');
 $newnavform      $form = '<div class="LC_Box" style="margin:0;">'.
 <br />               '<ul id="navigation'.$tid.'" class="LC_TabContent">'.
 $newsmppageform               '<li class="goback">'.
 <br />               '<a href="javascript:toContents('."'$jumpto'".');">'.
 $newsmpproblemform               '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
 <br />               '  alt="'.$backtext.'" />'.$backtext.'</a></li>';
 $newdropboxform      foreach my $name (reverse(sort(keys(%orderhash)))) {
 <br />          if($name ne '00'){
 $newexuploadform              if($activetab eq '' || $activetab ne $name){
 <br />                 $active = '';
 $newbulform              }elsif($activetab eq $name){
 <br />                 $active = 'class="active"';
 $newaboutmeform              }
 <br />              $form .= '<li style="float:right" '.$active
 $newaboutsomeoneform                  .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
 <br />                  .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>';
 $newgroupfileform          } else {
 <br />      $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>';
 $newrosterform  
 ENDFORM   }
        }      }
        if ($env{'form.pagepath'}) {      $form .= '</ul>';
            $r->print(<<ENDBLOCK);      $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">';
 $newsmpproblemform  
 <br />      if ($to_show ne '') {
 $newexuploadform          $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>';
 ENDBLOCK      }
        }      foreach my $field (keys(%orderhash)){
        $r->print('</td></tr>'."\n".   if($field ne '00'){
 '</table>');              if($activetab eq '' || $activetab ne $field){
        $r->print('</td></tr>');                  $active = 'style="display: none;float:left"';
     }              }elsif($activetab eq $field){
 # ----------------------------------------------------- Supplemental documents                  $active = 'style="display:block;float:left"';
     if (!$forcestandard) {              }
        $r->print('<tr><td class="LC_docs_document">');              $form .= '<div id="'.$field.$tid.'"'
 # '<h2>'.&mt('Supplemental Course Documents').                      .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
 #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');                      .'</div>';
        my $folder=$env{'form.folder'};          }
        unless ($folder=~/^supplemental/) {      }
    $folder='supplemental';      $form .= '</div></div>';
        }  
        if ($folder =~ /^supplemental$/ &&      return $form;
    (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {  }
           $env{'form.folderpath'} = 'supplemental&'.  
                                     &escape(&mt('Supplemental '.$type.' Documents'));  sub editing_js {
        }      my ($udom,$uname,$supplementalflag) = @_;
        my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);      my $now = time();
        if ($error) {      my %lt = &Apache::lonlocal::texthash(
    $r->print('<p><span class="LC_error">'.$error.'</span></p>');                                            p_mnf => 'Name of New Folder',
        }                                            t_mnf => 'New Folder',
        if ($allowed) {                                            p_mnp => 'Name of New Page',
    my $folderseq=                                            t_mnp => 'New Page',
        '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.                                            p_mxu => 'Title for the External Score',
        '.sequence';                                            p_msp => 'Name of Simple Course Page',
                                             p_msb => 'Title for the Problem',
    my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');                                            p_mdb => 'Title for the Drop Box',
                                             p_mbb => 'Title for the Discussion Board',
  my $supupdocform=(<<SUPDOCFORM);                                            p_mab => "Enter user:domain for User's Personal Information Page",
  <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">                                            p_mab2 => 'Personal Information Page of ',
  $fileupload                                            p_mab_alrt1 => 'Not a valid user:domain',
  <br />                                            p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
  <br />                                            p_chn => 'New Title',
  <span class="LC_nobreak">                                            p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
  $checkbox                                            p_rmr2a => 'Remove[_99]',
  </span>                                            p_rmr2b => '?[_99]',
  <br /><br />                                            p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
  $lt{'comment'}:<br />                                            p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
  <textarea cols=50 rows=4 name='comment'>                                            p_ctr2a => 'Cut[_98]',
  </textarea>                                            p_ctr2b => '?[_98]',
  <br />                                            rpck    => 'Enter number to pick (e.g., 3)',
  <input type="hidden" name="folderpath" value="$path" />                                          );
  <input type="hidden" name="cmd" value="upload_supplemental" />  
  <span class="LC_nobreak">      my $crstype = &Apache::loncommon::course_type();
  <input type="submit" value="$lt{'upld'}" />      my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
  $help{'Uploading_From_Harddrive'}      my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
  </span>      my $main_container_page;
  </form>      if ($docs_folderpath eq '') {
 SUPDOCFORM          if ($docs_pagepath ne '') {
               $main_container_page = 1;
  my $supnewfolderform=(<<SNFFORM);          }
  <form action="/adm/coursedocs" method="post" name="supnewfolder">      }
  <input type="hidden" name="folderpath" value="$path" />      my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
  <input type="hidden" name="importdetail" value="" />      my $toplevelsupp = &supplemental_base();
  <span class="LC_nobreak">  
  <input name="newfolder" type="button"      my $backtourl = '/adm/navmaps';
  onClick="javascript:makenewfolder(this.form,'$folderseq');"      if ($supplementalflag) {
  value="$lt{'newf'}" /> $help{'Adding_Folders'}          $backtourl = '/adm/supplemental';
  </span>      }
  </form>  
 SNFFORM      return <<ENDNEWSCRIPT;
   function makenewfolder(targetform,folderseq) {
       var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
  my $supnewextform=(<<SNEFORM);      if (foldername) {
  <form action="/adm/coursedocs" method="post" name="supnewext">         targetform.importdetail.value=escape(foldername)+"="+folderseq;
  <input type="hidden" name="folderpath" value="$path" />          targetform.submit();
  <input type="hidden" name="importdetail" value="" />      }
  <span class="LC_nobreak">  }
  <input name="newext" type="button"  
  onClick="javascript:makenewext('supnewext');"  function makenewpage(targetform,folderseq) {
  value="$lt{'extr'}" /> $help{'Adding_External_Resource'}      var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
  </span>      if (pagename) {
  </form>          targetform.importdetail.value=escape(pagename)+"="+folderseq;
 SNEFORM          targetform.submit();
       }
  my $supnewsylform=(<<SNSFORM);  }
  <form action="/adm/coursedocs" method="post" name="supnewsyl">  
  <input type="hidden" name="folderpath" value="$path" />  function makenewext(targetname) {
  <input type="hidden" name="importdetail"      this.document.forms.extimport.useform.value=targetname;
  value="Syllabus=/public/$coursedom/$coursenum/syllabus" />      this.document.forms.extimport.title.value='';
  <span class="LC_nobreak">      this.document.forms.extimport.url.value='';
  <input name="newsyl" type="submit" value="$lt{'syll'}" />      this.document.forms.extimport.residx.value='';
  $help{'Syllabus'}      window.open('/adm/rat/extpickframe.html');
  </span>  }
  </form>  
 SNSFORM  function edittext(targetname,residx,title,url) {
       this.document.forms.extimport.useform.value=targetname;
  my $supnewaboutmeform=(<<SNAMFORM);      this.document.forms.extimport.residx.value=residx;
  <form action="/adm/coursedocs" method="post" name="subnewaboutme">      this.document.forms.extimport.url.value=url;
  <input type="hidden" name="folderpath" value="$path" />      this.document.forms.extimport.title.value=title;
  <input type="hidden" name="importdetail"      window.open('/adm/rat/extpickframe.html');
  value="$plainname=/adm/$udom/$uname/aboutme" />  }
  <span class="LC_nobreak">  
  <input name="newaboutme" type="submit" value="$lt{'mypi'}" />  function makeexamupload() {
  $help{'My Personal Info'}     var title=prompt('$lt{"p_mxu"}');
  </span>     if (title) {
  </form>      this.document.forms.newexamupload.importdetail.value=
 SNAMFORM   escape(title)+'=/res/lib/templates/examupload.problem';
       this.document.forms.newexamupload.submit();
    $r->print(<<ENDSUPFORM);     }
 <ul class="LC_TabContent">  }
 <li>$lt{'nd'}</li>  
 <li>$lt{'sd'}</li>  function makesmppage() {
 <li>$lt{'hao'}</li>     var title=prompt('$lt{"p_msp"}');
 </ul>     if (title) {
 <table class="LC_docs_adddocs">      this.document.forms.newsmppg.importdetail.value=
 <tr><td>   escape(title)+'=/adm/$udom/$uname/$now/smppg';
 $supupdocform      this.document.forms.newsmppg.submit();
 </td>     }
 <td>  }
 $supnewfolderform  
 <br />  function makesmpproblem() {
 $supnewextform     var title=prompt('$lt{"p_msb"}');
 <br />     if (title) {
 $supnewsylform      this.document.forms.newsmpproblem.importdetail.value=
 <br />   escape(title)+'=/res/lib/templates/simpleproblem.problem';
 $supnewaboutmeform      this.document.forms.newsmpproblem.submit();
 </td></tr>     }
 </table></td></tr>  }
 ENDSUPFORM  
        }  function makedropbox() {
     }     var title=prompt('$lt{"p_mdb"}');
     $r->print('</table>');     if (title) {
     if ($allowed) {      this.document.forms.newdropbox.importdetail.value=
  $r->print('          escape(title)+'=/res/lib/templates/DropBox.problem';
 <form method="post" name="extimport" action="/adm/coursedocs">      this.document.forms.newdropbox.submit();
   <input type="hidden" name="title" />     }
   <input type="hidden" name="url" />  }
   <input type="hidden" name="useform" />  
   <input type="hidden" name="residx" />  function makebulboard() {
 </form>');     var title=prompt('$lt{"p_mbb"}');
     }     if (title) {
   } else {      this.document.forms.newbul.importdetail.value=
       unless ($upload_result eq 'phasetwo') {   escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
 # -------------------------------------------------------- This is showdoc mode      this.document.forms.newbul.submit();
           $r->print("<h1>".&mt('Uploaded Document').' - '.     }
  &Apache::lonnet::gettitle($r->uri).'</h1><p>'.  }
 &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".  
           &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) {
  }         var comp=new Array();
  $r->print(&Apache::loncommon::end_page());         comp=user.split(':');
  return OK;         if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
 }     if ((comp[0]) && (comp[1])) {
          this.document.forms.newaboutsomeone.importdetail.value=
      '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 sub editing_js {         this.document.forms.newaboutsomeone.submit();
     my ($udom,$uname) = @_;     } else {
     my $now = time();         alert("$lt{'p_mab_alrt1'}");
     my %lt = &Apache::lonlocal::texthash(     }
                                           p_mnf => 'Name of New Folder',  } else {
                                           t_mnf => 'New Folder',     alert("$lt{'p_mab_alrt2'}");
                                           p_mnp => 'Name of New Page',  }
                                           t_mnp => 'New Page',  }
                                           p_mxu => 'Title for the Uploaded Score',  }
                                           p_msp => 'Title for the Page',  
                                           p_msb => 'Title for the Problem',  function makeims() {
                                           p_mdb => 'Title for the Drop Box',  var caller = document.forms.ims.folder.value;
                                           p_mbb => 'Title for the Bulletin Board',  var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
                                           p_mab => "Enter user:domain for User's 'About Me' Page",  newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
                                           p_mab2 => "About [_99]",  newWindow.location.href = newlocation;
                                           p_mab_alrt1 => 'Not a valid user:domain',  }
                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',  
                                           p_chn => 'New Title',  function finishpick() {
                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',  var title=this.document.forms.extimport.title.value;
                                           p_rmr2a => 'Remove[_99]',  var url=this.document.forms.extimport.url.value;
                                           p_rmr2b => '?[_99]',  var form=this.document.forms.extimport.useform.value;
                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',  var residx=this.document.forms.extimport.residx.value;
                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',  eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
                                           p_ctr2a => 'Cut[_98]',  }
                                           p_ctr2b => '?[_98]'  
                                         );  function changename(folderpath,index,oldtitle,container,pagesymb) {
   var title=prompt('$lt{"p_chn"}',oldtitle);
     return <<ENDNEWSCRIPT;  if (title) {
 function makenewfolder(targetform,folderseq) {  this.document.forms.renameform.markcopy.value=-1;
     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');  this.document.forms.renameform.title.value=title;
     if (foldername) {  this.document.forms.renameform.cmd.value='rename_'+index;
        targetform.importdetail.value=escape(foldername)+"="+folderseq;  if (container == 'sequence') {
         targetform.submit();      this.document.forms.renameform.folderpath.value=folderpath;
     }  }
 }  if (container == 'page') {
       this.document.forms.renameform.pagepath.value=folderpath;
 function makenewpage(targetform,folderseq) {      this.document.forms.renameform.pagesymb.value=pagesymb;
     var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');  }
     if (pagename) {  this.document.forms.renameform.submit();
         targetform.importdetail.value=escape(pagename)+"="+folderseq;  }
         targetform.submit();  }
     }  
 }  function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
   if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
 function makenewext(targetname) {  this.document.forms.renameform.markcopy.value=-1;
     this.document.forms.extimport.useform.value=targetname;  this.document.forms.renameform.cmd.value='del_'+index;
     this.document.forms.extimport.title.value='';  if (container == 'sequence') {
     this.document.forms.extimport.url.value='';      this.document.forms.renameform.folderpath.value=folderpath;
     this.document.forms.extimport.residx.value='';  }
     window.open('/adm/rat/extpickframe.html');  if (container == 'page') {
 }      this.document.forms.renameform.pagepath.value=folderpath;
       this.document.forms.renameform.pagesymb.value=pagesymb;
 function edittext(targetname,residx,title,url) {  }
     this.document.forms.extimport.useform.value=targetname;  this.document.forms.renameform.submit();
     this.document.forms.extimport.residx.value=residx;  }
     this.document.forms.extimport.url.value=url;  }
     this.document.forms.extimport.title.value=title;  
     window.open('/adm/rat/extpickframe.html');  function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
 }  if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
   this.document.forms.renameform.cmd.value='cut_'+index;
 function makeexamupload() {  this.document.forms.renameform.markcopy.value=index;
    var title=prompt('$lt{"p_mxu"}');  this.document.forms.renameform.copyfolder.value=folder+'.'+container;
    if (title) {  if (container == 'sequence') {
     this.document.forms.newexamupload.importdetail.value=      this.document.forms.renameform.folderpath.value=folderpath;
  escape(title)+'=/res/lib/templates/examupload.problem';  }
     this.document.forms.newexamupload.submit();  if (container == 'page') {
    }      this.document.forms.renameform.pagepath.value=folderpath;
 }      this.document.forms.renameform.pagesymb.value=pagesymb;
   }
 function makesmppage() {  this.document.forms.renameform.submit();
    var title=prompt('$lt{"p_msp"}');  }
    if (title) {  }
     this.document.forms.newsmppg.importdetail.value=  
  escape(title)+'=/adm/$udom/$uname/$now/smppg';  function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
     this.document.forms.newsmppg.submit();  this.document.forms.renameform.markcopy.value=index;
    }  this.document.forms.renameform.copyfolder.value=folder+'.'+container;
 }  if (container == 'sequence') {
   this.document.forms.renameform.folderpath.value=folderpath;
 function makesmpproblem() {  }
    var title=prompt('$lt{"p_msb"}');  if (container == 'page') {
    if (title) {  this.document.forms.renameform.pagepath.value=folderpath;
     this.document.forms.newsmpproblem.importdetail.value=  this.document.forms.renameform.pagesymb.value=pagesymb;
  escape(title)+'=/res/lib/templates/simpleproblem.problem';  }
     this.document.forms.newsmpproblem.submit();  this.document.forms.renameform.submit();
    }  }
 }  
   function updatePick(targetform,index,caller) {
 function makedropbox() {      var pickitem = document.getElementById('rpick_'+index);
    var title=prompt('$lt{"p_mdb"}');      var picknumitem = document.getElementById('rpicknum_'+index);
    if (title) {      if (pickitem.checked) {
     this.document.forms.newdropbox.importdetail.value=          var picknum=prompt('$lt{"rpck"}',picknumitem.value);
         escape(title)+'=/res/lib/templates/DropBox.problem';          if (picknum == '' || picknum == null) {
     this.document.forms.newdropbox.submit();              if (caller == 'check') {
    }                  pickitem.checked=false;
 }                  return;
               }
 function makebulboard() {          } else {
    var title=prompt('$lt{"p_mbb"}');              picknum.toString();
    if (title) {              var regexdigit=/^\\d+\$/;
     this.document.forms.newbul.importdetail.value=              if (regexdigit.test(picknum)) {
  escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';                  picknumitem.value = picknum;
     this.document.forms.newbul.submit();                  targetform.changeparms.value='randompick';
    }                  targetform.submit();
 }              } else {
                   if (caller == 'check') {
 function makeabout() {                      pickitem.checked=false;
    var user=prompt("$lt{'p_mab'}");                  }
    if (user) {                  return;
        var comp=new Array();              }
        comp=user.split(':');          }
        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {      } else {
    if ((comp[0]) && (comp[1])) {          picknumitem.value = 0;
        this.document.forms.newaboutsomeone.importdetail.value=          targetform.changeparms.value='randompick';
    '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';          targetform.submit();
        this.document.forms.newaboutsomeone.submit();      }
    } else {  }
                alert("$lt{'p_mab_alrt1'}");  
            }  function unselectInactive(nav) {
        } else {  currentNav = document.getElementById(nav);
            alert("$lt{'p_mab_alrt2'}");  currentLis = currentNav.getElementsByTagName('LI');
        }  for (i = 0; i < currentLis.length; i++) {
    }          if (currentLis[i].className == 'goback') {
 }              currentLis[i].className = 'goback';
           } else {
 function makeims() {      if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
     var caller = document.forms.ims.folder.value;   currentLis[i].className = 'right';
     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";      } else {
     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");   currentLis[i].className = 'i';
     newWindow.location.href = newlocation;      }
 }          }
   }
   }
 function finishpick() {  
     var title=this.document.forms.extimport.title.value;  function hideAll(current, nav, data) {
     var url=this.document.forms.extimport.url.value;  unselectInactive(nav);
     var form=this.document.forms.extimport.useform.value;  if(current.className == 'right'){
     var residx=this.document.forms.extimport.residx.value;   current.className = 'right active'
     eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');   }else{
 }   current.className = 'active';
   }
 function changename(folderpath,index,oldtitle,container,pagesymb) {  currentData = document.getElementById(data);
     var title=prompt('$lt{"p_chn"}',oldtitle);  currentDivs = currentData.getElementsByTagName('DIV');
     if (title) {  for (i = 0; i < currentDivs.length; i++) {
  this.document.forms.renameform.markcopy.value=-1;   if(currentDivs[i].className == 'LC_ContentBox'){
  this.document.forms.renameform.title.value=title;   currentDivs[i].style.display = 'none';
  this.document.forms.renameform.cmd.value='rename_'+index;   }
         if (container == 'sequence') {  }
     this.document.forms.renameform.folderpath.value=folderpath;  }
         }  
         if (container == 'page') {  function openTabs(pageId) {
             this.document.forms.renameform.pagepath.value=folderpath;   tabnav = document.getElementById(pageId).getElementsByTagName('UL');
             this.document.forms.renameform.pagesymb.value=pagesymb;   if(tabnav.length > 2 ){
         }   currentNav = document.getElementById(tabnav[1].id);
         this.document.forms.renameform.submit();   currentLis = currentNav.getElementsByTagName('LI');
     }   for(i = 0; i< currentLis.length; i++){
 }   if(currentLis[i].className == 'active') {
    funcString = currentLis[i].onclick.toString();
 function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {   tab = funcString.split('"');
     if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {                                  if(tab.length < 2) {
  this.document.forms.renameform.markcopy.value=-1;                                     tab = funcString.split("'");
  this.document.forms.renameform.cmd.value='del_'+index;                                  }
         if (container == 'sequence') {   currentData = document.getElementById(tab[1]);
             this.document.forms.renameform.folderpath.value=folderpath;          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);
    unselectInactive(nav);
 function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {   current.className = 'active';
     if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {   currentData = document.getElementById(pageId);
  this.document.forms.renameform.cmd.value='cut_'+index;   currentData.style.display = 'block';
  this.document.forms.renameform.markcopy.value=index;          activeTab = pageId;
  this.document.forms.renameform.copyfolder.value=folder+'.'+container;          if (nav == 'mainnav') {
         if (container == 'sequence') {              var storedpath = "$docs_folderpath";
             this.document.forms.renameform.folderpath.value=folderpath;              if (storedpath == '') {
         }                  storedpath = "$docs_pagepath";
         if (container == 'page') {              }
             this.document.forms.renameform.pagepath.value=folderpath;              var storedpage = "$main_container_page";
             this.document.forms.renameform.pagesymb.value=pagesymb;              var reg = new RegExp("^supplemental");
         }              if (pageId == 'mainCourseDocuments') {
         this.document.forms.renameform.submit();                  if (storedpage == 1) {
     }                      document.simpleedit.folderpath.value = '';
 }                      document.uploaddocument.folderpath.value = '';
                   } else {
 function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {                      if (reg.test(storedpath)) {
     this.document.forms.renameform.markcopy.value=index;                          document.simpleedit.folderpath.value = '$toplevelmain';
     this.document.forms.renameform.copyfolder.value=folder+'.'+container;                          document.uploaddocument.folderpath.value = '$toplevelmain';
     if (container == 'sequence') {                          document.newext.folderpath.value = '$toplevelmain';
  this.document.forms.renameform.folderpath.value=folderpath;                      } else {
     }                          document.simpleedit.folderpath.value = storedpath;
     if (container == 'page') {                          document.uploaddocument.folderpath.value = storedpath;
  this.document.forms.renameform.pagepath.value=folderpath;                          document.newext.folderpath.value = storedpath;
  this.document.forms.renameform.pagesymb.value=pagesymb;                      }
     }                  }
     this.document.forms.renameform.submit();              } else {
 }                  if (reg.test(storedpath)) {
                       document.simpleedit.folderpath.value = storedpath;
                       document.supuploaddocument.folderpath.value = storedpath;
 ENDNEWSCRIPT                      document.supnewext.folderpath.value = storedpath;
 }                  } else {
 1;                      document.simpleedit.folderpath.value = '$toplevelsupp';
 __END__                      document.supuploaddocument.folderpath.value = '$toplevelsupp';
                       document.supnewext.folderpath.value = '$toplevelsupp';
                   }
 =head1 NAME              }
           }
 Apache::londocs.pm          resize_contentdiv('contentscroll','1','0');
    return false;
 =head1 SYNOPSIS  }
   
 This is part of the LearningOnline Network with CAPA project  function injectData(current, hiddenField, name, value) {
 described at http://www.lon-capa.org.   currentElement = document.getElementById(hiddenField);
    currentElement.name = name;
 =head1 SUBROUTINES   currentElement.value = value;
    current.submit();
 =over  }
   
 =item %help=()  function toContents(jumpto) {
       var newurl = '$backtourl';
 Available help topics      if (jumpto != '') {
           newurl = newurl+'?postdata='+jumpto;
 =item mapread()  ;
       }
 Mapread read maps into LONCAPA::map:: global arrays      location.href=newurl;
 @order and @resources, determines status  }
 sets @order - pointer to resources in right order  
 sets @resources - array with the resources with correct idx  ENDNEWSCRIPT
   }
 =item authorhosts()  
   sub resize_contentdiv_js {
 Return hash with valid author names      my ($tabidstr) = @_;
       my $viewport_js = &Apache::loncommon::viewport_geometry_js();
 =item dumpbutton()      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;
       var scrolltableid = 'table_'+scrollboxname;
 =item exportbutton()      var scrollbox;
       var scrolltable;
     Generate "export" button  
       if (document.getElementById("contenteditor") == null) {
 =item exportcourse()          return;
       }
 =item create_ims_store()  
       if (document.getElementById(scrollboxid) == null) {
 =item build_package()          return;
       } else {
 =item get_dependencies()          scrollbox = document.getElementById(scrollboxid);
       }
 =item process_content()  
       if (document.getElementById(scrolltableid) == null) {
 =item replicate_content()          return;
       } else {
 =item extract_media()          scrolltable = document.getElementById(scrolltableid);
       }
 =item store_template()  
       init_geometry();
 =item group_import()      var vph = Geometry.getViewportHeight();
       var vpw = Geometry.getViewportWidth();
     Imports the given (name, url) resources into the course  
     coursenum, coursedom, and folder must precede the list      var alltabs = ['$tabidstr'];
       var listwchange;
 =item breadcrumbs()      if (chkw == 1) {
           var contenteditorw = document.getElementById("contenteditor").offsetWidth;
 =item log_docs()          var contentlistw;
           var contentlistid = document.getElementById("contentlist");
 =item docs_change_log()          if (contentlistid != null) {
               contentlistw = document.getElementById("contentlist").offsetWidth;
 =item update_paste_buffer()          }
           var contentlistwstart = contentlistw;
 =item print_paste_buffer()  
           var scrollboxw = scrollbox.offsetWidth;
 =item do_paste_from_buffer()          var scrollboxscrollw = scrollbox.scrollWidth;
   
 =item update_parameter()          var offsetw = parseInt(vpw * 0.015);
           var paddingw = parseInt(vpw * 0.09);
 =item handle_edit_cmd()  
           var minscrollboxw = 250;
 =item editor()  
           var maxtabw = 0;
 =item process_file_upload()          var actabw = 0;
           for (var i=0; i<alltabs.length; i++) {
 =item process_secondary_uploads()              if (activeTab == alltabs[i]) {
                   actabw = document.getElementById(alltabs[i]).offsetWidth;
 =item is_supplemental_title()                  if (actabw > maxtabw) {
                       maxtabw = actabw;
 =item parse_supplemental_title()                  }
               } else {
 =item entryline()                  if (document.getElementById(alltabs[i]) != null) {
                       var thistab = document.getElementById(alltabs[i]);
 =item tiehash()                      thistab.style.visibility = 'hidden';
                       thistab.style.display = 'block';
 =item untiehash()                      var tabw = document.getElementById(alltabs[i]).offsetWidth;
                       thistab.style.display = 'none';
 =item checkonthis()                      thistab.style.visibility = '';
                       if (tabw > maxtabw) {
 check on this                          maxtabw = tabw;
                       }
 =item verifycontent()                  }
               }
 Verify Content          }
   
 =item devalidateversioncache() & checkversions()          if (maxtabw > 0) {
               var newscrollboxw;
 Check Versions              if (maxtabw+paddingw+scrollboxscrollw<contenteditorw) {
                   newscrollboxw = contenteditorw-paddingw-maxtabw;
 =item mark_hash_old()                  if (newscrollboxw < minscrollboxw) {
                       newscrollboxw = minscrollboxw;
 =item is_hash_old()                  }
                   scrollbox.style.width = newscrollboxw+"px";
 =item changewarning()                  if (newscrollboxw != scrollboxw) {
                       var newcontentlistw = newscrollboxw-offsetw;
 =item init_breadcrumbs()                      contentlistid.style.width = newcontentlistw+"px";
                   }
 Breadcrumbs for special functions              } else {
                   newscrollboxw = contenteditorw-paddingw-maxtabw;
 =back                  if (newscrollboxw < minscrollboxw) {
                       newscrollboxw = minscrollboxw;
 =cut                  }
                   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.481


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