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

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

Removed from v.1.270  
changed lines
  Added in v.1.328


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