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

version 1.275, 2007/06/11 21:27:23 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,$args)=@_;      }
     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) {
  &Apache::loncommon::start_data_table();          &print_paste_buffer($r,$container);
       }
     my $num = 0;      return;
     foreach my $embed_file (keys(%{$allfiles})) {  }
  $upload_output .= &Apache::loncommon::start_data_table_row().  
     '<td>'.$embed_file.'</td><td>';  sub process_file_upload {
  if ($args->{'ignore_remote_references'}      my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
     && $embed_file =~ m{^\w+://}) {  # upload a file, if present
     $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';      my $parseaction;
  } elsif ($args->{'error_on_invalid_names'}     if ($env{'form.parserflag'}) {
     && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {          $parseaction = 'parse';
           }
     $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';      my $phase_status;
           my $folder=$env{'form.folder'};
  } else {      if ($folder eq '') {
           $folder='default';
     $upload_output .='      }
            <input name="embedded_item_'.$num.'" type="file" value="bob" />      if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';          my $errtext='';
     my $attrib = join(':',@{$$allfiles{$embed_file}});          my $fatal=0;
     $upload_output .=          my $container='sequence';
  "\n\t\t".          if ($env{'form.pagepath'}) {
  '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.              $container='page';
  $attrib.'" />';          }
     if (exists($$codebase{$embed_file})) {          ($errtext,$fatal)=
  $upload_output .=                 &mapread($coursenum,$coursedom,$folder.'.'.$container);
     "\n\t\t".          if ($#LONCAPA::map::order<1) {
     '<input name="codebase_'.$num.'" type="hidden" value="'.              $LONCAPA::map::order[0]=1;
     &escape($$codebase{$embed_file}).'" />';              $LONCAPA::map::resources[1]='';
     }          }
  }          if ($fatal) {
  $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();              return 'failed';
  $num++;          }
     }          my $destination = 'docs/';
     $upload_output .= &Apache::loncommon::end_data_table().'<br />          if ($folder =~ /^supplemental/) {
    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />              $destination = 'supplemental/';
    <input type ="submit" value="'.&mt('Upload Listed Files').'" />          }
    '.&mt('(only files for which a location has been provided will be uploaded)').'          if (($folder eq 'default') || ($folder eq 'supplemental')) {
    </form>';              $destination .= 'default/';
     return $upload_output;          } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
 }              $destination .=  $2.'/';
           }
 sub process_secondary_uploads {  # this is for a course, not a user, so set coursedoc flag
     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;  # probably the only place in the system where this should be "1"
     my $folder=$env{'form.folder'};          my $newidx=&LONCAPA::map::getresidx();
     my $destination = 'docs/';          $destination .= $newidx;
     if ($folder =~ /^supplemental/) {          my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
         $destination = 'supplemental/';   $parseaction,$allfiles,
     }   $codebase);
     if (($folder eq 'default') || ($folder eq 'supplemental')) {          my $ext='false';
         $destination .= 'default/';          if ($url=~m{^http://}) { $ext='true'; }
     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {   $url     = &LONCAPA::map::qtunescape($url);
         $destination .=  $2.'/';          my $comment=$env{'form.comment'};
     }   $comment = &LONCAPA::map::qtunescape($comment);
     $destination .= $newidx;          if ($folder=~/^supplemental/) {
     my ($url,$filename);                $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);                    $env{'user.domain'}.'___&&&___'.$comment;
     ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});          }
     return $filename;  
 }          $LONCAPA::map::resources[$newidx]=
       $comment.':'.$url.':'.$ext.':normal:res';
 # --------------------------------------------------------------- An entry line          $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
           ($errtext,$fatal)=&storemap($coursenum,$coursedom,
 sub entryline {      $folder.'.'.$container);
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;          if ($fatal) {
     $title=&HTML::Entities::encode($title,'"<>&\'');              $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
     my $renametitle=$title;              return 'failed';
     my $foldertitle=$title;          } else {
     my $pagetitle=$title;              if ($parseaction eq 'parse') {
     my $orderidx=$LONCAPA::map::order[$index];                  my $total_embedded = keys(%{$allfiles});
     if ($title=~ /^(\d+)___&amp;&amp;&amp;___($match_username)___&amp;&amp;&amp;___($match_domain)___&amp;&amp;&amp;___(.*)$/ ) {                   if ($total_embedded > 0) {
  $foldertitle=&Apache::lontexconvert::msgtexconverted($4);                      my $num = 0;
  $renametitle=$4;      my $state = '
  $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.     <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
     &Apache::loncommon::plainname($2,$3).': <br />'.     <input type="hidden" name="cmd" value="upload_embedded" />
     $foldertitle;     <input type="hidden" name="newidx" value="'.$newidx.'" />
     }     <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
     $renametitle=~s/\\/\\\\/g;     <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
     $renametitle=~s/\&quot\;/\\\"/g;      $phase_status = 'phasetwo';
     my $line='<tr>';  
 # Edit commands                      $$upload_output .=
     my $container;   'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
     my $folderpath;   &Apache::loncommon::ask_for_embedded_content(
     if ($env{'form.folderpath'}) {                              '/adm/coursedocs',$state,$allfiles,$codebase);
         $container = 'sequence';                  } else {
  $folderpath=&escape($env{'form.folderpath'});                      $$upload_output .= 'No embedded items identified<br />';
  # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');                  }
     }              }
     my ($pagepath,$pagesymb);          }
     if ($env{'form.pagepath'}) {      }
         $container = 'page';      return $phase_status;
         $pagepath=&escape($env{'form.pagepath'});  }
         $pagesymb=&escape($env{'form.pagesymb'});  
     }  sub process_secondary_uploads {
     my $cpinfo='';      my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
     if ($env{'form.markedcopy_url'}) {      my $folder=$env{'form.folder'};
        $cpinfo='&markedcopy_url='.      my $destination = 'docs/';
                &escape($env{'form.markedcopy_url'}).      if ($folder =~ /^supplemental/) {
                '&markedcopy_title='.          $destination = 'supplemental/';
                &escape($env{'form.markedcopy_title'});      }
     }      if (($folder eq 'default') || ($folder eq 'supplemental')) {
     if ($allowed) {          $destination .= 'default/';
  my $incindex=$index+1;      } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
  my $selectbox='';          $destination .=  $2.'/';
  if (($folder!~/^supplemental/) &&      }
     ($#LONCAPA::map::order>0) &&       $destination .= $newidx;
     ((split(/\:/,      my ($url,$filename);
      $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]       $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
      ne '') &&       ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
     ((split(/\:/,      return $filename;
      $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]   }
      ne '')) {  
     $selectbox=  sub is_supplemental_title {
  '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.      my ($title) = @_;
  '<select name="newpos" onChange="this.form.submit()">';      return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
     for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {  }
  if ($i==$incindex) {  
     $selectbox.='<option value="" selected="1">('.$i.')</option>';  sub parse_supplemental_title {
  } else {      my ($title) = @_;
     $selectbox.='<option value="'.$i.'">'.$i.'</option>';  
  }      my ($foldertitle,$renametitle);
     }      if ($title =~ /&amp;&amp;&amp;/) {
     $selectbox.='</select>';   $title = &HTML::Entites::decode($title);
  }      }
  my %lt=&Apache::lonlocal::texthash(   if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
                 'up' => 'Move Up',   $renametitle=$4;
  'dw' => 'Move Down',   my ($time,$uname,$udom) = ($1,$2,$3);
  'rm' => 'Remove',   $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                 'ct' => 'Cut',   my $name =  &Apache::loncommon::plainname($uname,$udom);
  'rn' => 'Rename',   $name = &HTML::Entities::encode($name,'"<>&\'');
  'cp' => 'Copy');   $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
  my $nocopy=0;      $name.': <br />'.$foldertitle;
         my $nocut=0;      }
         if ($url=~/\.(page|sequence)$/) {      if (wantarray) {
     foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {   return ($title,$foldertitle,$renametitle);
  my ($title,$url,$ext,$type)=split(/\:/,$_);      }
  if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {      return $title;
     $nocopy=1;  }
     last;  
  }  # --------------------------------------------------------------- An entry line
     }  
  }  sub entryline {
         if ($url=~/^\/res\/lib\/templates\//) {       my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
            $nocopy=1;   
            $nocut=1;      my ($foldertitle,$pagetitle,$renametitle);
         }      if (&is_supplemental_title($title)) {
         my $copylink='&nbsp;';   ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
         my $cutlink='&nbsp;';   $pagetitle = $foldertitle;
         if ($env{'form.pagepath'}) {      } else {
            if (!$nocopy) {   $title=&HTML::Entities::encode($title,'"<>&\'');
                $copylink=(<<ENDCOPY);   $renametitle=$title;
 <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>   $foldertitle=$title;
 <font size="-2" color="#000099">$lt{'cp'}</font></a></td>   $pagetitle=$title;
 ENDCOPY      }
            }  
            if (!$nocut) {      my $orderidx=$LONCAPA::map::order[$index];
                $cutlink=(<<ENDCUT);     
 <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>  
 <font size="-2" color="#550044">$lt{'ct'}</font></a>      $renametitle=~s/\\/\\\\/g;
 ENDCUT      $renametitle=~s/\&quot\;/\\\"/g;
             }      $renametitle=~s/ /%20/g;
             $line.=(<<END);      my $line='<tr>';
 <form name="entry_$index" action="/adm/coursedocs" method="post">      my ($form_start,$form_end);
 <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />  # Edit commands
 <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />      my ($container, $type, $esc_path, $path, $symb);
 <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />      if ($env{'form.folderpath'}) {
 <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />   $type = 'folder';
 <input type="hidden" name="setparms" value="$orderidx" />          $container = 'sequence';
 <input type="hidden" name="changeparms" value="0" />   $esc_path=&escape($env{'form.folderpath'});
 <td><table border='0' cellspacing='2' cellpadding='0'>   $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 <tr><td bgcolor="#DDDDDD">   # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
 <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>      if ($env{'form.pagepath'}) {
 <tr><td bgcolor="#DDDDDD">          $type = $container = 'page';
 <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>          $esc_path=&escape($path = $env{'form.pagepath'});
 <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>   $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
 </table></td>          $symb=&escape($env{'form.pagesymb'});
 <td>$selectbox      }
 </td><td bgcolor="#DDDDDD">      my $cpinfo='';
 <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>      if ($allowed) {
 <font size="-2" color="#990000">$lt{'rm'}</font></a>   my $incindex=$index+1;
 $cutlink   my $selectbox='';
 <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>   if (($folder!~/^supplemental/) &&
 <font size="-2" color="#009900">$lt{'rn'}</font></a>      ($#LONCAPA::map::order>0) &&
 $copylink      ((split(/\:/,
 END       $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
         } else {       ne '') &&
            if (!$nocopy) {      ((split(/\:/,
                $copylink=(<<ENDCOPY);       $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
 <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>       ne '')) {
 <font size="-2" color="#000099">$lt{'cp'}</font></a></td>      $selectbox=
 ENDCOPY   '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
             }   '<select name="newpos" onChange="this.form.submit()">';
             if (!$nocut) {      for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                $cutlink=(<<ENDCUT);   if ($i==$incindex) {
 <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>      $selectbox.='<option value="" selected="1">('.$i.')</option>';
 <font size="-2" color="#550044">$lt{'ct'}</font></a>   } else {
 ENDCUT      $selectbox.='<option value="'.$i.'">'.$i.'</option>';
             }   }
             $line.=(<<END);       }
 <form name="entry_$index" action="/adm/coursedocs" method="post">      $selectbox.='</select>';
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   }
 <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />   my %lt=&Apache::lonlocal::texthash(
 <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />                  'up' => 'Move Up',
 <input type="hidden" name="setparms" value="$orderidx" />   'dw' => 'Move Down',
 <input type="hidden" name="changeparms" value="0" />   'rm' => 'Remove',
 <td><table border='0' cellspacing='2' cellpadding='0'>                  'ct' => 'Cut',
 <tr><td bgcolor="#DDDDDD">   'rn' => 'Rename',
 <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>   'cp' => 'Copy');
 <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>   my $nocopy=0;
 <tr><td bgcolor="#DDDDDD">          my $nocut=0;
 <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>          if ($url=~/\.(page|sequence)$/) {
 <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>      if ($url =~ m{/res/}) {
 </table></td>   # no copy for published maps
 <td>$selectbox   $nocopy = 1;
 </td><td bgcolor="#DDDDDD">      } else {
 <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>   foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
 <font size="-2" color="#990000">$lt{'rm'}</font></a>      my ($title,$url,$ext,$type)=split(/\:/,$item);
 $cutlink      if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
 <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>   $nocopy=1;
 <font size="-2" color="#009900">$lt{'rn'}</font></a>   last;
 $copylink      }
 END   }
         }      }
     }   }
 # Figure out what kind of a resource this is          if ($url=~/^\/res\/lib\/templates\//) {
     my ($extension)=($url=~/\.(\w+)$/);             $nocopy=1;
     my $uploaded=($url=~/^\/*uploaded\//);             $nocut=1;
     my $icon=&Apache::loncommon::icon($url);          }
     my $isfolder=0;          my $copylink='&nbsp;';
     my $ispage=0;          my $cutlink='&nbsp;';
     my $folderarg;  
     my $pagearg;   my $skip_confirm = 0;
     my $pagefile;   if ( $folder =~ /^supplemental/
     if ($uploaded) {       || ($url =~ m{( /smppg$
  if ($extension eq 'sequence') {      |/syllabus$
     $icon=$iconpath.'/folder_closed.gif';      |/aboutme$
     $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;      |/navmaps$
     $url='/adm/coursedocs?';      |/bulletinboard$
     $folderarg=$1;      |\.html$
     $isfolder=1;      |^/adm/wrapper/ext)}x)) {
         } elsif ($extension eq 'page') {      $skip_confirm = 1;
             $icon=$iconpath.'/page.gif';   }
             $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;  
             $pagearg=$1;   if (!$nocopy) {
             $url='/adm/coursedocs?';      $copylink=(<<ENDCOPY);
             $ispage=1;  <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
  } else {  ENDCOPY
     &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);          }
  }   if (!$nocut) {
     }      $cutlink=(<<ENDCUT);
     $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;  <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {  ENDCUT
  my $symb=&Apache::lonnet::symbclean(          }
           &Apache::lonnet::declutter('uploaded/'.   $form_start = (<<END);
            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.     <form  action="/adm/coursedocs" method="post">
            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.     <input type="hidden" name="${type}path" value="$path" />
            '.sequence').     <input type="hidden" name="${type}symb" value="$symb" />
            '___'.$residx.'___'.     <input type="hidden" name="setparms" value="$orderidx" />
    &Apache::lonnet::declutter($url));     <input type="hidden" name="changeparms" value="0" />
  (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);  END
  $url=&Apache::lonnet::clutter($url);          $form_end = '</form>';
  if ($url=~/^\/*uploaded\//) {   $line.=(<<END);
     $url=~/\.(\w+)$/;  <td>
     my $embstyle=&Apache::loncommon::fileembstyle($1);     <table class="LC_docs_entry_move">
     if (($embstyle eq 'img') || ($embstyle eq 'emb')) {        <tr>
  $url='/adm/wrapper'.$url;           <td>
     } elsif ($embstyle eq 'ssi') {              <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>
  #do nothing with these           </td>
     } elsif ($url!~/\.(sequence|page)$/) {        </tr>
  $url='/adm/coursedocs/showdoc'.$url;        <tr>
     }          <td>
  } elsif ($url=~m|^/ext/|) {              <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>
     $url='/adm/wrapper'.$url;          </td>
  }        </tr>
         if (&Apache::lonnet::symbverify($symb,$url)) {      </table>
     $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);  </td>
         } else {  <td>
             $url='';     $form_start
         }     $selectbox
  if ($container eq 'page') {     $form_end
     my $symb=$env{'form.pagesymb'};  </td>
           <td class="LC_docs_entry_commands">
     $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);     <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
     $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);  $cutlink
  }     <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
     }  $copylink
     my $parameterset='&nbsp;';  </td>
     if ($isfolder || $extension eq 'sequence') {  END
  my $foldername=&escape($foldertitle);  
  my $folderpath=$env{'form.folderpath'};      }
  if ($folderpath) { $folderpath.='&' };  # Figure out what kind of a resource this is
 # Append randompick number, hidden, and encrypted with ":" to foldername,       my ($extension)=($url=~/\.(\w+)$/);
 # so it gets transferred between levels      my $uploaded=($url=~/^\/*uploaded\//);
  $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,      my $icon=&Apache::loncommon::icon($url);
                                               'parameter_randompick'))[0]      my $isfolder=0;
                                                .':'.((&LONCAPA::map::getparameter($orderidx,      my $ispage=0;
                                               'parameter_hiddenresource'))[0]=~/^yes$/i)      my $folderarg;
                                                .':'.((&LONCAPA::map::getparameter($orderidx,      my $pagearg;
                                               'parameter_encrypturl'))[0]=~/^yes$/i);      my $pagefile;
  $url.='folderpath='.&escape($folderpath).$cpinfo;      if ($uploaded) {
  $parameterset='<label>'.&mt('Randomly Pick: ').   if ($extension eq 'sequence') {
     '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randpick_'.$orderidx.'" value="'.      $icon=$iconpath.'/folder_closed.gif';
     (&LONCAPA::map::getparameter($orderidx,      $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
                                               'parameter_randompick'))[0].      $url='/adm/coursedocs?';
                                               '" />'.      $folderarg=$1;
 '<font size="-2"><a href="javascript:void(0)">'.&mt('Save').'</a></font></label>';      $isfolder=1;
                  } elsif ($extension eq 'page') {
     }              $icon=$iconpath.'/page.gif';
     if ($ispage) {              $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
         my $pagename=&escape($pagetitle);              $pagearg=$1;
         my $pagepath;              $url='/adm/coursedocs?';
         my $folderpath=$env{'form.folderpath'};              $ispage=1;
         if ($folderpath) { $pagepath = $folderpath.'&' };   } else {
         $pagepath.=$pagearg.'&'.$pagename;      &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
  my $symb=$env{'form.pagesymb'};   }
  if (!$symb) {      }
     my $path='uploaded/'.     
  $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.      my $orig_url = $url;
  $env{'course.'.$env{'request.course.id'}.'.num'}.'/';      my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
     $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',      if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
        $residx,   my $symb=&Apache::lonnet::symbclean(
        $path.$pagearg.'.page');            &Apache::lonnet::declutter('uploaded/'.
  }             $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
  $url.='pagepath='.&escape($pagepath).             $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
     '&pagesymb='.&escape($symb).$cpinfo;             '.sequence').
     }             '___'.$residx.'___'.
     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.     &Apache::lonnet::declutter($url));
  '" border="0"></a></td>'.   (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
         "<td bgcolor='#FFFFBB'>".($url?"<a href=\"$url\">":'').$title.   $url=&Apache::lonnet::clutter($url);
         ($url?'</a>':' <font size="-2">'.&mt('(re-initialize course to access)').'</font>')."</td>";   if ($url=~/^\/*uploaded\//) {
     if (($allowed) && ($folder!~/^supplemental/)) {      $url=~/\.(\w+)$/;
   my %lt=&Apache::lonlocal::texthash(      my $embstyle=&Apache::loncommon::fileembstyle($1);
        'hd' => 'Hidden',      if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
        'ec' => 'URL hidden');   $url='/adm/wrapper'.$url;
  my $enctext=      } elsif ($embstyle eq 'ssi') {
     ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');   #do nothing with these
  my $hidtext=      } elsif ($url!~/\.(sequence|page)$/) {
     ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');   $url='/adm/coursedocs/showdoc'.$url;
  $line.=(<<ENDPARMS);      }
 <td bgcolor="#BBBBFF"><font size='-2'>   } elsif ($url=~m|^/ext/|) {
 <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>      $url='/adm/wrapper'.$url;
 <td bgcolor="#BBBBFF"><font size='-2'>      $external = 1;
 <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>   }
 <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>          if (&Apache::lonnet::symbverify($symb,$url)) {
 ENDPARMS      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
     }          } else {
     $line.="</form></tr>";              $url='';
     return $line;          }
 }   if ($container eq 'page') {
       my $symb=$env{'form.pagesymb'};
 # ---------------------------------------------------------------- tie the hash          
       $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
 sub tiehash {      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
     my ($mode)=@_;   }
     $hashtied=0;      }
     if ($env{'request.course.fn'}) {      my ($parameterset,$rand_order_text) = ('&nbsp;', '&nbsp;');
  if ($mode eq 'write') {      if ($isfolder || $extension eq 'sequence') {
     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",   my $foldername=&escape($foldertitle);
     &GDBM_WRCREAT(),0640)) {   my $folderpath=$env{'form.folderpath'};
                 $hashtied=2;   if ($folderpath) { $folderpath.='&' };
     }  # Append randompick number, hidden, and encrypted with ":" to foldername,
  } else {  # so it gets transferred between levels
     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",   $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
     &GDBM_READER(),0640)) {                                                'parameter_randompick'))[0]
                 $hashtied=1;                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
     }                                                'parameter_hiddenresource'))[0]=~/^yes$/i)
  }                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
     }                                                    'parameter_encrypturl'))[0]=~/^yes$/i)
 }                                                 .':'.((&LONCAPA::map::getparameter($orderidx,
                                                 'parameter_randomorder'))[0]=~/^yes$/i);
 sub untiehash {   $url.='folderpath='.&escape($folderpath).$cpinfo;
     if ($hashtied) { untie %hash; }   $parameterset='<label>'.&mt('Randomly Pick: ').
     $hashtied=0;      '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
     return OK;      (&LONCAPA::map::getparameter($orderidx,
 }                                                'parameter_randompick'))[0].
                                                 '" />'.
 # --------------------------------------------------------------- check on this  '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
       my $ro_set=
 sub checkonthis {      ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
     my ($r,$url,$level,$title)=@_;   $rand_order_text ='
     $url=&unescape($url);  <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';  
     $alreadyseen{$url}=1;      }
     $r->rflush();      if ($ispage) {
     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {          my $pagename=&escape($pagetitle);
        $r->print("\n<br />");          my $pagepath;
        for (my $i=0;$i<=$level*5;$i++) {          my $folderpath=$env{'form.folderpath'};
            $r->print('&nbsp;');          if ($folderpath) { $pagepath = $folderpath.'&' };
        }          $pagepath.=$pagearg.'&'.$pagename;
        $r->print('<a href="'.$url.'" target="cat">'.   my $symb=$env{'form.pagesymb'};
  ($title?$title:$url).'</a> ');   if (!$symb) {
        if ($url=~/^\/res\//) {      my $path='uploaded/'.
   my $result=&Apache::lonnet::repcopy(   $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                               &Apache::lonnet::filelocation('',$url));   $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
           if ($result eq 'ok') {      $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
              $r->print('<font color="green">'.&mt('ok').'</font>');         $residx,
              $r->rflush();         $path.$pagearg.'.page');
              &Apache::lonnet::countacc($url);   }
              $url=~/\.(\w+)$/;   $url.='pagepath='.&escape($pagepath).
              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {      '&amp;pagesymb='.&escape($symb).$cpinfo;
  $r->print('<br />');      }
                  $r->rflush();      if ($external) {
                  for (my $i=0;$i<=$level*5;$i++) {   my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
                      $r->print('&nbsp;');   $external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
                  }      } else {
                  $r->print('- '.&mt('Rendering').': ');   undef($external);
  my ($errorcount,$warningcount)=split(/:/,      }
        &Apache::lonnet::ssi_body($url,      $line.='
        ('grade_target'=>'web',    <td class="LC_docs_entry_icon">
  'return_only_error_and_warning_counts' => 1)));      '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
                  if (($errorcount) ||    </td>
                      ($warningcount)) {    <td class="LC_docs_entry_title">
      if ($errorcount) {      '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.    </td>";
   $errorcount.' '.      if (($allowed) && ($folder!~/^supplemental/)) {
   &mt('error(s)').'</b></font> ');    my %lt=&Apache::lonlocal::texthash(
                      }         'hd' => 'Hidden',
      if ($warningcount) {         'ec' => 'URL hidden');
                         $r->print('<font color="blue">'.   my $enctext=
   $warningcount.' '.      ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
   &mt('warning(s)').'</font>');   my $hidtext=
                      }      ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
                  } else {   $line.=(<<ENDPARMS);
                      $r->print('<font color="green">'.&mt('ok').'</font>');    <td class="LC_docs_entry_parameter">
                  }      $form_start
                  $r->rflush();      <label><input type="checkbox" name="hiddenresource_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
              }      $form_end
      my $dependencies=    </td>
                 &Apache::lonnet::metadata($url,'dependencies');    <td class="LC_docs_entry_parameter">
              foreach (split(/\,/,$dependencies)) {      $form_start
  if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {      <label><input type="checkbox" name="encrypturl_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
                     &checkonthis($r,$_,$level+1);      $form_end
                  }    </td>
              }    <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
           } elsif ($result eq 'unavailable') {    <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');  ENDPARMS
           } elsif ($result eq 'not_found') {      }
       unless ($url=~/\$/) {      $line.="</tr>";
   $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');      return $line;
       } else {  }
   $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');  
       }  =pod
           } else {  
              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');  =item tiehash()
           }  
       }  tie the hash
    }  
 }  =cut
   
   sub tiehash {
 #      my ($mode)=@_;
 # ----------------------------------------------------------------- List Symbs      $hashtied=0;
 #       if ($env{'request.course.fn'}) {
 sub list_symbs {   if ($mode eq 'write') {
     my ($r) = @_;      if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
       &GDBM_WRCREAT(),0640)) {
     $r->print(&Apache::loncommon::start_page('Symb List'));                  $hashtied=2;
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));      }
     my $navmap = Apache::lonnavmaps::navmap->new();   } else {
     $r->print("<pre>\n");      if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
     foreach my $res ($navmap->retrieveResources()) {      &GDBM_READER(),0640)) {
  $r->print($res->compTitle()."\t".$res->symb()."\n");                  $hashtied=1;
     }      }
     $r->print("\n</pre>\n");   }
     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');      }    
 }  }
   
   sub untiehash {
 #      if ($hashtied) { untie %hash; }
 # -------------------------------------------------------------- Verify Content      $hashtied=0;
 #       return OK;
 sub verifycontent {  }
     my ($r) = @_;  
     my $type = &Apache::loncommon::course_type();  
    my $loaderror=&Apache::lonnet::overloaderror($r);  
    if ($loaderror) { return $loaderror; }  
    $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));  sub checkonthis {
    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));      my ($r,$url,$level,$title)=@_;
    $hashtied=0;      $url=&unescape($url);
    undef %alreadyseen;      $alreadyseen{$url}=1;
    %alreadyseen=();      $r->rflush();
    &tiehash();      if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
    foreach (keys %hash) {         $r->print("\n<br />");
        if ($hash{$_}=~/\.(page|sequence)$/) {         if ($level==0) {
    if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {             $r->print("<br />");
        $r->print('<hr /><font color="red">'.         }
  &mt('The following sequence or page is included more than once in your '.$type.': ').         for (my $i=0;$i<=$level*5;$i++) {
  &unescape($hash{$_}).'</font><br />'.             $r->print('&nbsp;');
  &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));         }
    }         $r->print('<a href="'.$url.'" target="cat">'.
        }   ($title?$title:$url).'</a> ');
        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {         if ($url=~/^\/res\//) {
            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});    my $result=&Apache::lonnet::repcopy(
        }                                &Apache::lonnet::filelocation('',$url));
    }            if ($result eq 'ok') {
    &untiehash();               $r->print('<span class="LC_success">'.&mt('ok').'</span>');
    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.               $r->rflush();
      &mt('Return to DOCS').'</a>');               &Apache::lonnet::countacc($url);
 }               $url=~/\.(\w+)$/;
                if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
    $r->print('<br />');
 # -------------------------------------------------------------- Check Versions                   $r->rflush();
                    for (my $i=0;$i<=$level*5;$i++) {
 sub devalidateversioncache {                       $r->print('&nbsp;');
     my $src=shift;                   }
     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.                   $r->print('- '.&mt('Rendering:').' ');
   &Apache::lonnet::clutter($src));   my ($errorcount,$warningcount)=split(/:/,
 }         &Apache::lonnet::ssi_body($url,
          ('grade_target'=>'web',
 sub checkversions {   'return_only_error_and_warning_counts' => 1)));
     my ($r) = @_;                   if (($errorcount) ||
     my $type = &Apache::loncommon::course_type();                       ($warningcount)) {
     $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));       if ($errorcount) {
     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));                          $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
     my $header='';                            &mt('[quant,_1,error]',$errorcount).'</span>');
     my $startsel='';                       }
     my $monthsel='';       if ($warningcount) {
     my $weeksel='';                          $r->print('<span class="LC_warning">'.
     my $daysel='';                            &mt('[quant,_1,warning]',$warningcount).'</span>');
     my $allsel='';                       }
     my %changes=();                   } else {
     my $starttime=0;                       $r->print('<span class="LC_success">'.&mt('ok').'</span>');
     my $haschanged=0;                   }
     my %setversions=&Apache::lonnet::dump('resourceversions',                   $r->rflush();
   $env{'course.'.$env{'request.course.id'}.'.domain'},               }
   $env{'course.'.$env{'request.course.id'}.'.num'});       my $dependencies=
                   &Apache::lonnet::metadata($url,'dependencies');
     $hashtied=0;               foreach my $dep (split(/\,/,$dependencies)) {
     &tiehash();   if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
     my %newsetversions=();                      &checkonthis($r,$dep,$level+1);
     if ($env{'form.setmostrecent'}) {                   }
  $haschanged=1;               }
  foreach (keys %hash) {            } elsif ($result eq 'unavailable') {
     if ($_=~/^ids\_(\/res\/.+)$/) {               $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
  $newsetversions{$1}='mostrecent';            } elsif ($result eq 'not_found') {
                 &devalidateversioncache($1);        unless ($url=~/\$/) {
     }    $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
  }        } else {
     } elsif ($env{'form.setcurrent'}) {    $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
  $haschanged=1;        }
  foreach (keys %hash) {            } else {
     if ($_=~/^ids\_(\/res\/.+)$/) {               $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
  my $getvers=&Apache::lonnet::getversion($1);            }
  if ($getvers>0) {         }
     $newsetversions{$1}=$getvers;      }
     &devalidateversioncache($1);  }
  }  
     }  
  }  
     } elsif ($env{'form.setversions'}) {  =pod
  $haschanged=1;  
  foreach (keys %env) {  =item list_symbs()
     if ($_=~/^form\.set_version_(.+)$/) {  
  my $src=$1;  List Symbs
  if (($env{$_}) && ($env{$_} ne $setversions{$src})) {  
     $newsetversions{$src}=$env{$_};  =cut
     &devalidateversioncache($src);  
  }  sub list_symbs {
     }      my ($r) = @_;
  }  
     }      my $type = &Apache::loncommon::course_type();
     if ($haschanged) {      $r->print(&Apache::loncommon::start_page('Symb List'));
         if (&Apache::lonnet::put('resourceversions',\%newsetversions,      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
   $env{'course.'.$env{'request.course.id'}.'.domain'},      my $navmap = Apache::lonnavmaps::navmap->new();
   $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {      if (!defined($navmap)) {
     $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');          $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
  } else {                    '<div class="LC_error">'.
     $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</font></h1>');                    &mt('Unable to retrieve information about course contents').
  }                    '</div>');
  &mark_hash_old();          &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
     }      } else {
     &changewarning($r,'');          $r->print("<pre>\n");
     if ($env{'form.timerange'} eq 'all') {          foreach my $res ($navmap->retrieveResources()) {
 # show all documents      $r->print($res->compTitle()."\t".$res->symb()."\n");
  $header=&mt('All Documents in '.$type);          }
  $allsel=1;          $r->print("\n</pre>\n");
  foreach (keys %hash) {      }
     if ($_=~/^ids\_(\/res\/.+)$/) {      $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
  my $src=$1;  }
  $changes{$src}=1;  
     }  
  }  sub verifycontent {
     } else {      my ($r) = @_;
 # show documents which changed      my $type = &Apache::loncommon::course_type();
  %changes=&Apache::lonnet::dump     my $loaderror=&Apache::lonnet::overloaderror($r);
  ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},     if ($loaderror) { return $loaderror; }
                      $env{'course.'.$env{'request.course.id'}.'.num'});     $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
  my $firstkey=(keys %changes)[0];     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
  unless ($firstkey=~/^error\:/) {     $hashtied=0;
     unless ($env{'form.timerange'}) {     undef %alreadyseen;
  $env{'form.timerange'}=604800;     %alreadyseen=();
     }     &tiehash();
     my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '     foreach my $key (keys(%hash)) {
  .&mt('seconds');         if ($hash{$key}=~/\.(page|sequence)$/) {
     if ($env{'form.timerange'}==-1) {     if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
  $seltext='since start of course';         $r->print('<hr /><span class="LC_error">'.
  $startsel='selected';   &mt('The following sequence or page is included more than once in your '.$type.': ').
  $env{'form.timerange'}=time;   &unescape($hash{$key}).'</span><br />'.
     }   &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
     $starttime=time-$env{'form.timerange'};     }
     if ($env{'form.timerange'}==2592000) {         }
  $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';         if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
  $monthsel='selected';             &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
     } elsif ($env{'form.timerange'}==604800) {         }
  $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';     }
  $weeksel='selected';     &untiehash();
     } elsif ($env{'form.timerange'}==86400) {     $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
  $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';       &mt('Return to DOCS').'</a>');
  $daysel='selected';  }
     }  
     $header=&mt('Content changed').' '.$seltext;  
  } else {  sub devalidateversioncache {
     $header=&mt('No content modifications yet.');      my $src=shift;
  }      &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
     }    &Apache::lonnet::clutter($src));
     %setversions=&Apache::lonnet::dump('resourceversions',  }
   $env{'course.'.$env{'request.course.id'}.'.domain'},  
   $env{'course.'.$env{'request.course.id'}.'.num'});  sub checkversions {
     my %lt=&Apache::lonlocal::texthash      my ($r) = @_;
       ('st' => 'Version changes since start of '.$type,      my $type = &Apache::loncommon::course_type();
        'lm' => 'Version changes since last Month',      $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
        'lw' => 'Version changes since last Week',      $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
        'sy' => 'Version changes since Yesterday',      my $header='';
                'al' => 'All Resources (possibly large output)',      my $startsel='';
        'sd' => 'Display',      my $monthsel='';
        'fi' => 'File',      my $weeksel='';
        'md' => 'Modification Date',      my $daysel='';
                'mr' => 'Most recently published Version',      my $allsel='';
        've' => 'Version used in '.$type,      my %changes=();
                'vu' => 'Set Version to be used in '.$type,      my $starttime=0;
 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',      my $haschanged=0;
 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',      my %setversions=&Apache::lonnet::dump('resourceversions',
 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',    $env{'course.'.$env{'request.course.id'}.'.domain'},
        'di' => 'Differences');    $env{'course.'.$env{'request.course.id'}.'.num'});
     $r->print(<<ENDHEADERS);  
 <form action="/adm/coursedocs" method="post">      $hashtied=0;
 <input type="hidden" name="versions" value="1" />      &tiehash();
 <input type="submit" name="setmostrecent" value="$lt{'sm'}" />      my %newsetversions=();
 <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />      if ($env{'form.setmostrecent'}) {
 <select name="timerange">   $haschanged=1;
 <option value='all' $allsel>$lt{'al'}</option>   foreach my $key (keys(%hash)) {
 <option value="-1" $startsel>$lt{'st'}</option>      if ($key=~/^ids\_(\/res\/.+)$/) {
 <option value="2592000" $monthsel>$lt{'lm'}</option>   $newsetversions{$1}='mostrecent';
 <option value="604800" $weeksel>$lt{'lw'}</option>                  &devalidateversioncache($1);
 <option value="86400" $daysel>$lt{'sy'}</option>      }
 </select>   }
 <input type="submit" name="display" value="$lt{'sd'}" />      } elsif ($env{'form.setcurrent'}) {
 <h3>$header</h3>   $haschanged=1;
 <input type="submit" name="setversions" value="$lt{'sv'}" />   foreach my $key (keys(%hash)) {
 <table border="0">      if ($key=~/^ids\_(\/res\/.+)$/) {
 ENDHEADERS   my $getvers=&Apache::lonnet::getversion($1);
     foreach (sort keys %changes) {   if ($getvers>0) {
  if ($changes{$_}>$starttime) {      $newsetversions{$1}=$getvers;
     my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);      &devalidateversioncache($1);
     my $currentversion=&Apache::lonnet::getversion($_);   }
     if ($currentversion<0) {      }
  $currentversion=&mt('Could not be determined.');   }
     }      } elsif ($env{'form.setversions'}) {
     my $linkurl=&Apache::lonnet::clutter($_);   $haschanged=1;
     $r->print(   foreach my $key (keys(%env)) {
       '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.      if ($key=~/^form\.set_version_(.+)$/) {
       &Apache::lonnet::gettitle($linkurl).   my $src=$1;
                       '</b></font></td></tr>'.   if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.      $newsetversions{$src}=$env{$key};
                       '<td colspan="4">'.      &devalidateversioncache($src);
                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.   }
       '</a></td></tr>'.      }
                       '<tr><td></td>'.   }
                       '<td title="'.$lt{'md'}.'">'.      }
       &Apache::lonlocal::locallocaltime(      if ($haschanged) {
                            &Apache::lonnet::metadata($root.'.'.$extension,          if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                                                      'lastrevisiondate')    $env{'course.'.$env{'request.course.id'}.'.domain'},
                                                         ).    $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                       '</td>'.      $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.   } else {
                       '<font size="+1">'.$currentversion.'</font>'.      $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
                       '</nobr></td>'.   }
                       '<td title="'.$lt{'ve'}.'"><nobr>In '.$type.': '.   &mark_hash_old();
                       '<font size="+1">');      }
 # Used in course      &changewarning($r,'');
     my $usedversion=$hash{'version_'.$linkurl};      if ($env{'form.timerange'} eq 'all') {
     if (($usedversion) && ($usedversion ne 'mostrecent')) {  # show all documents
  $r->print($usedversion);   $header=&mt('All Documents in '.$type);
     } else {   $allsel=1;
  $r->print($currentversion);   foreach my $key (keys(%hash)) {
     }      if ($key=~/^ids\_(\/res\/.+)$/) {
     $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.   my $src=$1;
                       '<nobr>Use: ');   $changes{$src}=1;
 # Set version      }
     $r->print(&Apache::loncommon::select_form($setversions{$linkurl},   }
       'set_version_'.$linkurl,      } else {
       ('select_form_order' =>  # show documents which changed
        ['',1..$currentversion,'mostrecent'],   %changes=&Apache::lonnet::dump
        '' => '',   ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
        'mostrecent' => 'most recent',                       $env{'course.'.$env{'request.course.id'}.'.num'});
        map {$_,$_} (1..$currentversion))));   my $firstkey=(keys(%changes))[0];
     $r->print('</nobr></td></tr><tr><td></td>');   unless ($firstkey=~/^error\:/) {
     my $lastold=1;      unless ($env{'form.timerange'}) {
     for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {   $env{'form.timerange'}=604800;
  my $url=$root.'.'.$prevvers.'.'.$extension;      }
  if (&Apache::lonnet::metadata($url,'lastrevisiondate')<      my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
     $starttime) {   .&mt('seconds');
     $lastold=$prevvers;      if ($env{'form.timerange'}==-1) {
  }   $seltext='since start of course';
     }   $startsel='selected';
             #    $env{'form.timerange'}=time;
             # Code to figure out how many version entries should go in      }
             # each of the four columns      $starttime=time-$env{'form.timerange'};
             my $entries_per_col = 0;      if ($env{'form.timerange'}==2592000) {
             my $num_entries = ($currentversion-$lastold);   $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
             if ($num_entries % 4 == 0) {   $monthsel='selected';
                 $entries_per_col = $num_entries/4;      } elsif ($env{'form.timerange'}==604800) {
             } else {   $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                 $entries_per_col = $num_entries/4 + 1;   $weeksel='selected';
             }      } elsif ($env{'form.timerange'}==86400) {
             my $entries_count = 0;   $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
             $r->print('<td valign="top"><font size="-2">');    $daysel='selected';
             my $cols_output = 1;      }
             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {      $header=&mt('Content changed').' '.$seltext;
  my $url=$root.'.'.$prevvers.'.'.$extension;   } else {
  $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).      $header=&mt('No content modifications yet.');
   '">'.&mt('Version').' '.$prevvers.'</a> ('.   }
   &Apache::lonlocal::locallocaltime(      }
                                 &Apache::lonnet::metadata($url,      %setversions=&Apache::lonnet::dump('resourceversions',
                                                           'lastrevisiondate')    $env{'course.'.$env{'request.course.id'}.'.domain'},
                                                             ).    $env{'course.'.$env{'request.course.id'}.'.num'});
   ')');      my %lt=&Apache::lonlocal::texthash
  if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {        ('st' => 'Version changes since start of '.$type,
                     $r->print(' <a href="/adm/diff?filename='.         'lm' => 'Version changes since last Month',
       &Apache::lonnet::clutter($root.'.'.$extension).         'lw' => 'Version changes since last Week',
       '&versionone='.$prevvers.         'sy' => 'Version changes since Yesterday',
       '">'.&mt('Diffs').'</a>');                 'al' => 'All Resources (possibly large output)',
  }         'sd' => 'Display',
  $r->print('</nobr><br />');         'fi' => 'File',
                 if (++$entries_count % $entries_per_col == 0) {         'md' => 'Modification Date',
                     $r->print('</font></td>');                 'mr' => 'Most recently published Version',
                     if ($cols_output != 4) {         've' => 'Version used in '.$type,
                         $r->print('<td valign="top"><font size="-2">');                 'vu' => 'Set Version to be used in '.$type,
                         $cols_output++;  'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
                     }  'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                 }  'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
     }         'di' => 'Differences');
             while($cols_output++ < 4) {      $r->print(<<ENDHEADERS);
                 $r->print('</font></td><td><font>')  <form action="/adm/coursedocs" method="post">
             }  <input type="hidden" name="versions" value="1" />
     $r->print('</font></td></tr>'."\n");  <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
  }  <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
     }  <select name="timerange">
     $r->print('</table></form>');  <option value='all' $allsel>$lt{'al'}</option>
     $r->print('<h1>'.&mt('Done').'.</h1>');  <option value="-1" $startsel>$lt{'st'}</option>
   <option value="2592000" $monthsel>$lt{'lm'}</option>
     &untiehash();  <option value="604800" $weeksel>$lt{'lw'}</option>
 }  <option value="86400" $daysel>$lt{'sy'}</option>
   </select>
 sub mark_hash_old {  <input type="submit" name="display" value="$lt{'sd'}" />
     my $retie_hash=0;  <h3>$header</h3>
     if ($hashtied) {  <input type="submit" name="setversions" value="$lt{'sv'}" />
  $retie_hash=1;  <table border="0">
  &untiehash();  ENDHEADERS
     }      foreach my $key (sort(keys(%changes))) {
     &tiehash('write');   if ($changes{$key}>$starttime) {
     $hash{'old'}=1;      my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
     &untiehash();      my $currentversion=&Apache::lonnet::getversion($key);
     if ($retie_hash) { &tiehash(); }      if ($currentversion<0) {
 }   $currentversion=&mt('Could not be determined.');
       }
 sub is_hash_old {      my $linkurl=&Apache::lonnet::clutter($key);
     my $untie_hash=0;      $r->print(
     if (!$hashtied) {        '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
  $untie_hash=1;        &Apache::lonnet::gettitle($linkurl).
  &tiehash();                        '</b></font></td></tr>'.
     }                        '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
     my $return=$hash{'old'};                        '<td colspan="4">'.
     if ($untie_hash) { &untiehash(); }                        '<a href="'.$linkurl.'" target="cat">'.$linkurl.
     return $return;        '</a></td></tr>'.
 }                        '<tr><td></td>'.
                         '<td title="'.$lt{'md'}.'">'.
 sub changewarning {        &Apache::lonlocal::locallocaltime(
     my ($r,$postexec,$message,$url)=@_;                             &Apache::lonnet::metadata($root.'.'.$extension,
     if (!&is_hash_old()) { return; }                                                       'lastrevisiondate')
     my $pathvar='folderpath';                                                          ).
     my $path=&escape($env{'form.folderpath'});                        '</td>'.
     if (!defined($url)) {                        '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
  if (defined($env{'form.pagepath'})) {                        '<font size="+1">'.$currentversion.'</font>'.
     $pathvar='pagepath';                        '</span></td>'.
     $path=&escape($env{'form.pagepath'});                        '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
     $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});                        '<font size="+1">');
  }  # Used in course
  $url='/adm/coursedocs?'.$pathvar.'='.$path;      my $usedversion=$hash{'version_'.$linkurl};
     }      if (($usedversion) && ($usedversion ne 'mostrecent')) {
     my $course_type = &Apache::loncommon::course_type();   $r->print($usedversion);
     if (!defined($message)) {      } else {
  $message='Changes will become active for your current session after [_1], or the next time you log in.';   $r->print($currentversion);
     }      }
     $r->print("\n\n".      $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
 '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".                         '<span class="LC_nobreak">Use: ');
 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.  # Set version
 '<input type="hidden" name="orgurl" value="'.$url.      $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.        'set_version_'.$linkurl,
 &mt($message,' <input type="hidden" name="'.        ('select_form_order' =>
     $env{'request.role'}.'" value="1" /><input type="button" value="'.         ['',1..$currentversion,'mostrecent'],
     &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').         '' => '',
 $help{'Caching'}.'</font></h3></form>'."\n\n");         'mostrecent' => 'most recent',
 }         map {$_,$_} (1..$currentversion))));
       $r->print('</span></td></tr><tr><td></td>');
 # =========================================== Breadcrumbs for special functions      my $lastold=1;
       for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
 sub init_breadcrumbs {   my $url=$root.'.'.$prevvers.'.'.$extension;
     my ($form,$text)=@_;   if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
     &Apache::lonhtmlcommon::clear_breadcrumbs();      $starttime) {
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",      $lastold=$prevvers;
     text=>&Apache::loncommon::course_type()." Documents",   }
     faq=>273,      }
     bug=>'Instructor Interface',              #
                                             help => 'Docs_Adding_Course_Doc'});              # Code to figure out how many version entries should go in
     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',              # each of the four columns
     text=>$text,              my $entries_per_col = 0;
     faq=>273,              my $num_entries = ($currentversion-$lastold);
     bug=>'Instructor Interface'});              if ($num_entries % 4 == 0) {
 }                  $entries_per_col = $num_entries/4;
               } else {
 # ================================================================ Main Handler                  $entries_per_col = $num_entries/4 + 1;
 sub handler {              }
     my $r = shift;              my $entries_count = 0;
     &Apache::loncommon::content_type($r,'text/html');              $r->print('<td valign="top"><font size="-2">');
     $r->send_http_header;              my $cols_output = 1;
     return OK if $r->header_only;              for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
     my $type = &Apache::loncommon::course_type();   my $url=$root.'.'.$prevvers.'.'.$extension;
    $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
 # --------------------------------------------- Initialize help topics for this    '">'.&mt('Version').' '.$prevvers.'</a> ('.
     foreach ('Adding_Course_Doc','Main_Course_Documents',    &Apache::lonlocal::locallocaltime(
      'Adding_External_Resource','Navigate_Content',                                  &Apache::lonnet::metadata($url,
      'Adding_Folders','Docs_Overview', 'Load_Map',                                                            'lastrevisiondate')
      'Supplemental','Score_Upload_Form','Adding_Pages',                                                              ).
      'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',    ')');
      'Check_Resource_Versions','Verify_Content') {   if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
  $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);                      $r->print(' <a href="/adm/diff?filename='.
     }        &Apache::lonnet::clutter($root.'.'.$extension).
     # Composite help files        '&versionone='.$prevvers.
     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(        '">'.&mt('Diffs').'</a>');
     'Docs_About_Syllabus,Docs_Editing_Templated_Pages');   }
     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(   $r->print('</span><br />');
     'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');                  if (++$entries_count % $entries_per_col == 0) {
     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(                      $r->print('</font></td>');
     'Option_Response_Simple');                      if ($cols_output != 4) {
     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(                          $r->print('<td valign="top"><font size="-2">');
     'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');                          $cols_output++;
     $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');      }
     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');              while($cols_output++ < 4) {
                   $r->print('</font></td><td><font>')
 # does this user have privileges to modify docs              }
     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});      $r->print('</font></td></tr>'."\n");
   if ($allowed && $env{'form.verify'}) {   }
       &init_breadcrumbs('verify','Verify Content');      }
       &verifycontent($r);      $r->print('</table></form>');
   } elsif ($allowed && $env{'form.listsymbs'}) {      $r->print('<h1>'.&mt('Done').'.</h1>');
       &init_breadcrumbs('listsymbs','List Symbs');  
       &list_symbs($r);      &untiehash();
   } elsif ($allowed && $env{'form.docslog'}) {  }
       &init_breadcrumbs('docslog','Show Log');  
       &docs_change_log($r);  sub mark_hash_old {
   } elsif ($allowed && $env{'form.versions'}) {      my $retie_hash=0;
       &init_breadcrumbs('versions','Check/Set Resource Versions');      if ($hashtied) {
       &checkversions($r);   $retie_hash=1;
   } elsif ($allowed && $env{'form.dumpcourse'}) {   &untiehash();
       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');      }
       &dumpcourse($r);      &tiehash('write');
   } elsif ($allowed && $env{'form.exportcourse'}) {      $hash{'old'}=1;
       &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');      &untiehash();
       &exportcourse($r);      if ($retie_hash) { &tiehash(); }
   } else {  }
 # is this a standard course?  
   sub is_hash_old {
     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);      my $untie_hash=0;
     my $forcestandard = 0;      if (!$hashtied) {
     my $forcesupplement;   $untie_hash=1;
     my $script='';   &tiehash();
     my $showdoc=0;      }
     my $containertag;      my $return=$hash{'old'};
     my $uploadtag;      if ($untie_hash) { &untiehash(); }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      return $return;
     ['folderpath','pagepath',  }
      'pagesymb','markedcopy_url',  
      'markedcopy_title']);  sub changewarning {
     if ($env{'form.folderpath'}) {      my ($r,$postexec,$message,$url)=@_;
  my (@folderpath)=split('&',$env{'form.folderpath'});      if (!&is_hash_old()) { return; }
  $env{'form.foldername'}=&unescape(pop(@folderpath));      my $pathvar='folderpath';
  $env{'form.folder'}=pop(@folderpath);      my $path=&escape($env{'form.folderpath'});
     }      if (!defined($url)) {
     if ($env{'form.pagepath'}) {   if (defined($env{'form.pagepath'})) {
         my (@pagepath)=split('&',$env{'form.pagepath'});      $pathvar='pagepath';
         $env{'form.pagename'}=&unescape(pop(@pagepath));      $path=&escape($env{'form.pagepath'});
         $env{'form.folder'}=pop(@pagepath);      $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
         $containertag = '<input type="hidden" name="pagepath" value="" />'.   }
     '<input type="hidden" name="pagesymb" value="" />';   $url='/adm/coursedocs?'.$pathvar.'='.$path;
         $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.      }
     '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';      my $course_type = &Apache::loncommon::course_type();
     }      if (!defined($message)) {
     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {   $message='Changes will become active for your current session after [_1], or the next time you log in.';
        $showdoc='/'.$1;      }
     }      $r->print("\n\n".
     unless ($showdoc) { # got called from remote  '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
        if (($env{'form.folder'}=~/^(?:group|default)_/) ||   '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {  '<input type="hidden" name="orgurl" value="'.$url.
            $forcestandard = 1;  '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.
        }   &mt($message,' <input type="hidden" name="'.
        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);      $env{'request.role'}.'" value="1" /><input type="button" value="'.
       &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
        if ($allowed) {   $help{'Caching'}.'</span></h3></form>'."\n\n");
          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);  }
          $script=&Apache::lonratedt::editscript('simple');   
        }  
     } else { # got called in sequence from course  sub init_breadcrumbs {
        $allowed=0;      my ($form,$text)=@_;
     }      &Apache::lonhtmlcommon::clear_breadcrumbs();
       &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
 # get course data      text=>"Edit ".&Apache::loncommon::course_type(),
     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};      faq=>273,
     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};      bug=>'Instructor Interface',
                                               help => 'Docs_Adding_Course_Doc'});
 # get personal data       &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
     my $uname=$env{'user.name'};      text=>$text,
     my $udom=$env{'user.domain'};      faq=>273,
     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));      bug=>'Instructor Interface'});
   }
 # graphics settings  
   
     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");  
   
     if ($allowed) {  sub handler {
  $script .= &editing_js($udom,$uname);      my $r = shift;
     }      &Apache::loncommon::content_type($r,'text/html');
 # -------------------------------------------------------------------- Body tag      $r->send_http_header;
     $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';      return OK if $r->header_only;
     $r->print(&Apache::loncommon::start_page("$type Documents", $script,      my $type = &Apache::loncommon::course_type();
      {'force_register' => $showdoc,}).  
       &Apache::loncommon::help_open_menu('','',273,'RAT'));  
     # --------------------------------------------- Initialize help topics for this
   my %allfiles = ();      foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
   my %codebase = ();                 'Adding_External_Resource','Navigate_Content',
   my ($upload_result,$upload_output);                 'Adding_Folders','Docs_Overview', 'Load_Map',
   if ($allowed) {                 'Supplemental','Score_Upload_Form','Adding_Pages',
       if (($env{'form.uploaddoc.filename'}) &&                 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
   ($env{'form.cmd'}=~/^upload_(\w+)/)) {                 'Check_Resource_Versions','Verify_Content') {
 # Process file upload - phase one - upload and parse primary file.     $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
           $upload_result = &process_file_upload(\$upload_output,$coursenum,      }
  $coursedom,\%allfiles,      # Composite help files
  \%codebase,$1);      $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
           if ($upload_result eq 'phasetwo') {      'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
               $r->print($upload_output);      $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
           }      'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
       } elsif ($env{'form.phasetwo'}) {      $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
           my %newname = ();      'Option_Response_Simple');
           my %origname = ();      $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
           my %attribs = ();      'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
           my $updateflag = 0;      $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
           my $residx = $env{'form.newidx'};    'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
           my $primary_url = &unescape($env{'form.primaryurl'});      $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
 # Process file upload - phase two - gather secondary files.      $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {  
               if ($env{'form.embedded_item_'.$i.'.filename'}) {  # does this user have privileges to modify docs
                   my $javacodebase;      my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);    if ($allowed && $env{'form.verify'}) {
                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});        &init_breadcrumbs('verify','Verify Content');
                   if (exists($env{'form.embedded_codebase_'.$i})) {        &verifycontent($r);
                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});      } elsif ($allowed && $env{'form.listsymbs'}) {
                       $origname{$i} =~ s#^\Q$javacodebase\E/##;         &init_breadcrumbs('listsymbs','List Symbs');
                   }        &list_symbs($r);
                   my @attributes = ();    } elsif ($allowed && $env{'form.docslog'}) {
                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {        &init_breadcrumbs('docslog','Show Log');
                       @attributes = split/:/,$env{'form.embedded_attrib_'.$i};        &docs_change_log($r);
                   } else {    } elsif ($allowed && $env{'form.versions'}) {
                       @attributes = ($env{'form.embedded_attrib_'.$i});        &init_breadcrumbs('versions','Check/Set Resource Versions');
                   }        &checkversions($r);
                   foreach (@attributes) {    } elsif ($allowed && $env{'form.dumpcourse'}) {
                       push(@{$attribs{$i}},&unescape($_));        &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
                   }        &dumpcourse($r);
                   if ($javacodebase) {    } elsif ($allowed && $env{'form.exportcourse'}) {
                       $codebase{$i} = $javacodebase;        &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
                       $codebase{$i} =~ s#/$##;        &exportcourse($r);
                       $updateflag = 1;    } else {
                   }  # is this a standard course?
               }  
               unless ($newname{$i} eq $origname{$i}) {      my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
                   $updateflag = 1;      my $forcestandard = 0;
               }      my $forcesupplement;
           }      my $script='';
 # Process file upload - phase three - modify primary file      my $showdoc=0;
           if ($updateflag) {      my $containertag;
               my ($content,$rtncode);      my $uploadtag;
               my $updateflag = 0;  
               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);  
               if ($getstatus eq 'ok') {      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   foreach my $item (keys %newname) {      ['folderpath','pagepath',
                       if ($newname{$item} ne $origname{$item}) {       'pagesymb']);
                           my $attrib_regexp = '';  # No folderpath, no pagepath, see if we have something stored
                           if (@{$attribs{$item}} > 1) {      if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
                               $attrib_regexp = join('|',@{$attribs{$item}});          &Apache::loncommon::restore_course_settings('docs_folderpath',
                           } else {                                                {'folderpath' => 'scalar'});
                               $attrib_regexp = $attribs{$item}[0];      }
                           }      if (!$env{'form.folderpath'}) {
                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {          &Apache::loncommon::restore_course_settings('docs_folderpath',
                           }                                                 {'pagepath' => 'scalar'});
                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;       }
                       }      if ($env{'form.pagepath'}) {
                       if (exists($codebase{$item})) {         $env{'form.folderpath'}='';
                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs      }
                       }      if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
                   }          $env{'form.folderpath'} = 'supplemental&'.
 # Save edited file.                                    &escape(&mt('Supplemental '.$type.' Documents')).'&'.
                   my $saveresult;                                    $env{'form.folderpath'};
                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};      }
                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};      &Apache::loncommon::store_course_settings('docs_folderpath',
                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);                                                  {'pagepath' => 'scalar',
               } else {                                                   'folderpath' => 'scalar'});
                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);       if ($env{'form.folderpath'}) {
               }   my (@folderpath)=split('&',$env{'form.folderpath'});
           }   $env{'form.foldername'}=&unescape(pop(@folderpath));
       }   $env{'form.folder'}=pop(@folderpath);
   }      }
       if ($env{'form.pagepath'}) {
   unless ($showdoc ||  $upload_result eq 'phasetwo') {          my (@pagepath)=split('&',$env{'form.pagepath'});
 # -----------------------------------------------------------------------------          $env{'form.pagename'}=&unescape(pop(@pagepath));
        my %lt=&Apache::lonlocal::texthash(          $env{'form.folder'}=pop(@pagepath);
                 'uplm' => 'Upload a new main '.lc($type).' document',          $containertag = '<input type="hidden" name="pagepath" value="" />'.
                 'upls' => 'Upload a new supplemental '.lc($type).' document',      '<input type="hidden" name="pagesymb" value="" />';
                 'impp' => 'Import a document',          $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
                 'pubd' => 'Published documents',      '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
  'copm' => 'All documents out of a published map into this folder',      }
                 'spec' => 'Special documents',      if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                 'upld' => 'Upload Document',         $showdoc='/'.$1;
                 'srch' => 'Search',      }
                 'impo' => 'Import',      unless ($showdoc) { # got called from remote
  'book' => 'Import Bookmarks',         if (($env{'form.folder'}=~/^(?:group|default)_/) ||
                 'selm' => 'Select Map',            ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
                 'load' => 'Load Map',             $forcestandard = 1;
                 'reco' => 'Recover Deleted Resources',         }
                 'newf' => 'New Folder',         $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
                 'newp' => 'New Composite Page',  
                 'extr' => 'External Resource',         if ($allowed) {
                 'syll' => 'Syllabus',           &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                 'navc' => 'Navigate Contents',           $script=&Apache::lonratedt::editscript('simple');
                 'sipa' => 'Simple Page',         }
                 'sipr' => 'Simple Problem',      } else { # got called in sequence from course
                 'drbx' => 'Drop Box',         $allowed=0;
                 'scuf' => 'Score Upload Form',      }
                 'bull' => 'Bulletin Board',  
                 'mypi' => 'My Personal Info',  # get course data
                 'grpo' => 'Group Files',      my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  'abou' => 'About User',      my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                 'imsf' => 'Import IMS package',  
                 'file' =>  'File',  # get personal data
                 'title' => 'Title',      my $uname=$env{'user.name'};
                 'comment' => 'Comment',      my $udom=$env{'user.domain'};
                 'parse' => 'If HTML file, upload embedded images/multimedia files'      my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
   );  
 # -----------------------------------------------------------------------------  # graphics settings
     if ($allowed) {  
        my $dumpbut=&dumpbutton();      $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
        my $exportbut=&exportbutton();  
        my %lt=&Apache::lonlocal::texthash(      if ($allowed) {
  'vc' => 'Verify Content',   $script .= &editing_js($udom,$uname);
  'cv' => 'Check/Set Resource Versions',      }
  'ls' => 'List Symbs',  # -------------------------------------------------------------------- Body tag
                                          'sl' => 'Show Log'      $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
   );      my $brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}];
       $r->print(&Apache::loncommon::start_page("$type Documents", $script,
        my $folderpath=$env{'form.folderpath'};      {'force_register' => $showdoc,
        if (!$folderpath) {                                       'bread_crumbs' => $brcrum}).
    if ($env{'form.folder'} eq '' ||        &Apache::loncommon::help_open_menu('','',273,'RAT'));
        $env{'form.folder'} eq 'supplemental') {   
        $folderpath='default&'.    my %allfiles = ();
    &escape(&mt('Main '.$type.' Documents'));    my %codebase = ();
    }    my ($upload_result,$upload_output);
        }    if ($allowed) {
        unless ($env{'form.pagepath'}) {        if (($env{'form.uploaddoc.filename'}) &&
            $containertag = '<input type="hidden" name="folderpath" value="" />';    ($env{'form.cmd'}=~/^upload_(\w+)/)) {
            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';  # Process file upload - phase one - upload and parse primary file.  
        }    undef($hadchanges);
             $upload_result = &process_file_upload(\$upload_output,$coursenum,
        $r->print(<<ENDCOURSEVERIFY);   $coursedom,\%allfiles,
 <form name="renameform" method="post" action="/adm/coursedocs">   \%codebase,$1);
 <input type="hidden" name="title" />    if ($hadchanges) {
 <input type="hidden" name="cmd" />        &mark_hash_old();
 <input type="hidden" name="markcopy" />    }
 $containertag            if ($upload_result eq 'phasetwo') {
 </form>                $r->print($upload_output);
 <form name="simpleedit" method="post" action="/adm/coursedocs">            }
 <input type="hidden" name="importdetail" value="" />        } elsif ($env{'form.phasetwo'}) {
 $uploadtag            my %newname = ();
 </form>            my %origname = ();
 <form action="/adm/coursedocs" method="post" name="courseverify">            my %attribs = ();
 <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">            my $updateflag = 0;
 <tr><td bgcolor="#DDDDCC">            my $residx = $env{'form.newidx'};
 <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}            my $primary_url = &unescape($env{'form.primaryurl'});
 </td><td bgcolor="#DDDDCC">  # Process file upload - phase two - gather secondary files.
     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}            for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
 $dumpbut                if ($env{'form.embedded_item_'.$i.'.filename'}) {
 $exportbut                    my $javacodebase;
 </td><td bgcolor="#DDDDCC">                    $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
     <input type="submit" name="listsymbs" value="$lt{'ls'}" />                    $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
 </td><td bgcolor="#DDDDCC">                    if (exists($env{'form.embedded_codebase_'.$i})) {
     <input type="hidden" name="folder" value="$env{'form.folder'}" />                        $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});  
     <input type="submit" name="docslog" value="$lt{'sl'}" />                        $origname{$i} =~ s#^\Q$javacodebase\E/##;
 </td></tr></table>                    }
 </form>                    my @attributes = ();
 ENDCOURSEVERIFY                    if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',                        @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
      &mt('Editing the Table of Contents for your '.$type)));                    } else {
     }                        @attributes = ($env{'form.embedded_attrib_'.$i});
 # --------------------------------------------------------- Standard documents                    }
     $r->print('<table border=2 cellspacing=4 cellpadding=4>');                    foreach my $attr (@attributes) {
     if (($standard) && ($allowed) && (!$forcesupplement)) {                        push(@{$attribs{$i}},&unescape($attr));
  $r->print('<tr><td bgcolor="#BBBBBB">');                    }
 #  '<h2>'.&mt('Main Course Documents').                    if ($javacodebase) {
 #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');                        $codebase{$i} = $javacodebase;
        my $folder=$env{'form.folder'};                        $codebase{$i} =~ s#/$##;
        if ($folder eq '' || $folder eq 'supplemental') {                        $updateflag = 1;
            $folder='default';                    }
    $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));                }
        }                unless ($newname{$i} eq $origname{$i}) {
        my $postexec='';                    $updateflag = 1;
        if ($folder eq 'default') {                }
    $r->print('<script>this.window.name="loncapaclient";</script>');            }
        } else {  # Process file upload - phase three - modify primary file
            #$postexec='self.close();';            if ($updateflag) {
        }                my ($content,$rtncode);
        $hadchanges=0;                my $updateflag = 0;
        &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);                my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
        if ($hadchanges) {                if ($getstatus eq 'ok') {
    &mark_hash_old()                    foreach my $item (keys(%newname)) {
        }                        if ($newname{$item} ne $origname{$item}) {
        &changewarning($r,$postexec);                            my $attrib_regexp = '';
        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.                            if (@{$attribs{$item}} > 1) {
                      '.sequence';                                $attrib_regexp = join('|',@{$attribs{$item}});
        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.                            } else {
                      '.page';                                $attrib_regexp = $attribs{$item}[0];
  my $container='sequence';                            }
  if ($env{'form.pagepath'}) {                            if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
     $container='page';                            }
  }                            $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
  my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;                        }
        $r->print(<<ENDFORM);                        if (exists($codebase{$item})) {
 <table cellspacing=4 cellpadding=4><tr>                            $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
 <th bgcolor="#DDDDDD">$lt{'uplm'}</th>                        }
 <th bgcolor="#DDDDDD">$lt{'impp'}</th>                    }
 <th bgcolor="#DDDDDD">$lt{'spec'}</th>  # Save edited file.
 </tr>                    my $saveresult;
 <tr><td bgcolor="#DDDDDD">                    my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
 $lt{'file'}:<br />                    my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">                    my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
 <input type="file" name="uploaddoc" size="40">                } else {
 <br />                    &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
 $lt{'title'}:<br />                }
 <input type="text" size="50" name="comment">            }
 $uploadtag        }
 <input type="hidden" name="cmd" value="upload_default">    }
 <br />  
 <nobr>    unless ($showdoc ||  $upload_result eq 'phasetwo') {
 <label>$lt{'parse'}?  # -----------------------------------------------------------------------------
 <input type="checkbox" name="parserflag" />         my %lt=&Apache::lonlocal::texthash(
 </label>                  'uplm' => 'Upload a new main '.lc($type).' document',
 </nobr>                  'upls' => 'Upload a new supplemental '.lc($type).' document',
 <br />                  'impp' => 'Import a document',
 <br />                  'pubd' => 'Published Documents',
 <nobr>   'copm' => 'All documents out of a published map into this folder',
 <input type="submit" value="$lt{'upld'}">                  'upld' => 'Upload Document',
  $help{'Uploading_From_Harddrive'}                  'srch' => 'Search',
 </nobr>                  'impo' => 'Import',
 </form>   'book' => 'Import Bookmarks',
 </td>                  'selm' => 'Select Map',
 <td bgcolor="#DDDDDD">                  'load' => 'Load Map',
 <form action="/adm/coursedocs" method="post" name="simpleeditdefault">                  'reco' => 'Recover Deleted Resources',
 $lt{'pubd'}<br />                  'newf' => 'New Folder',
 $uploadtag                  'newp' => 'New Composite Page',
 <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}" />                  'extr' => 'External Resource',
 <br />                  'syll' => 'Syllabus',
 <nobr>                  'navc' => 'Navigate Contents',
 <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}" />                  'sipa' => 'Simple Page',
 $help{'Importing_LON-CAPA_Resource'}                  'sipr' => 'Simple Problem',
 </nobr>                  'drbx' => 'Drop Box',
 <br />                  'scuf' => 'Score Upload Form',
 <input type=button onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />                  'bull' => 'Bulletin Board',
 <p>                  'mypi' => 'My Personal Info',
 <hr />                  'grpo' => 'Group Files',
 $lt{'copm'}<br />                  'rost' => 'Course Roster',
 <input type="text" size="40" name="importmap"><br />   'abou' => 'About User',
 <nobr><input type=button                   'imsf' => 'Import IMS package',
 onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"                  'file' =>  'File',
 value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">                  'title' => 'Title',
 $help{'Load_Map'}</nobr>                  'comment' => 'Comment',
 </p>                  'parse' => 'Upload embedded images/multimedia files if HTML file!',
 </form>   'nd' => 'New Document',
 <hr />   'pm' => 'Published Map',
 <form action="/adm/groupsort" method="post" name="recover">   'sd' => 'Special Document',
 <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />   'mo' => 'More Options',
 </form>   'hao' => 'Hide all Options'
 ENDFORM    );
        unless ($env{'form.pagepath'}) {  # -----------------------------------------------------------------------------
    $r->print(<<ENDFORM);   my $fileupload=(<<FIUP);
 <hr />   $lt{'file'}:<br />
 <form action="/adm/coursedocs" method="post" name="newext">   <input type="file" name="uploaddoc" size="40" />
 $uploadtag  FIUP
 <input type="hidden" name="importdetail" value="" />  
 <nobr>   my $checkbox=(<<CHBO);
 <input name="newext" type="button" onClick="javascript:makenewext('newext');"   <!-- <label>$lt{'parse'}?
 value="$lt{'extr'}" /> $help{'Adding_External_Resource'}   <input type="checkbox" name="parserflag" />
 </nobr>   </label> -->
 </form>   <label>
 <br /><form action="/adm/imsimportdocs" method="post" name="ims">   <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
 <input type="hidden" name="folder" value="$folder" />   </label>
 <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />  CHBO
 </nobr>  
 </form>   my $fileuploadform=(<<FUFORM);
 ENDFORM   <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
        }   $fileupload
        $r->print('</td><td bgcolor="#DDDDDD">');   <br />
        unless ($env{'form.pagepath'}) {   $lt{'title'}:<br />
            $r->print(<<ENDFORM);   <input type="text" size="50" name="comment" />
 <br /><form action="/adm/coursedocs" method="post" name="newfolder">   $uploadtag
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   <input type="hidden" name="cmd" value="upload_default" />
 <input type="hidden" name="importdetail" value="" />   <br />
 <nobr>   <span class="LC_nobreak">
 <input name="newfolder" type="button"   $checkbox
 onClick="javascript:makenewfolder(this.form,'$folderseq');"   </span>
 value="$lt{'newf'}" />$help{'Adding_Folders'}   <br />
 </nobr>   <br />
 </form>   <span class="LC_nobreak">
 <br /><form action="/adm/coursedocs" method="post" name="newpage">   <input type="submit" value="$lt{'upld'}" />
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   $help{'Uploading_From_Harddrive'}
 <input type="hidden" name="importdetail" value="" />   </span>
 <nobr>   </form>
 <input name="newpage" type="button"  FUFORM
 onClick="javascript:makenewpage(this.form,'$pageseq');"  
 value="$lt{'newp'}" />$help{'Adding_Pages'}   my $simpleeditdefaultform=(<<SEDFFORM);
 </nobr>   <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 </form>   $lt{'pubd'}<br />
 <br /><form action="/adm/coursedocs" method="post" name="newsyl">   $uploadtag
 $uploadtag   <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />
 <input type="hidden" name="importdetail"    <br />
 value="Syllabus=/public/$coursedom/$coursenum/syllabus" />   <span class="LC_nobreak">
 <nobr>   <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />
 <input name="newsyl" type="submit" value="$lt{'syll'}" />    $help{'Importing_LON-CAPA_Resource'}
  $help{'Syllabus'}   </span>
 </nobr>   <br />
 </form>   <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
 <br /><form action="/adm/coursedocs" method="post" name="newnav">   <hr />
 $uploadtag   <p>
 <input type="hidden" name="importdetail"    $lt{'copm'}<br />
 value="Navigate Content=/adm/navmaps" />   <input type="text" size="40" name="importmap" /><br />
 <nobr>   <span class="LC_nobreak"><input type="button"
 <input name="newnav" type="submit" value="$lt{'navc'}" />   onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 $help{'Navigate_Content'}   value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
 </nobr>   $help{'Load_Map'}</span>
 </form>   </p>
 <br /><form action="/adm/coursedocs" method="post" name="newsmppg">   </form>
 $uploadtag  SEDFFORM
 <input type="hidden" name="importdetail" value="" />  
 <nobr>   my $extresourcesform=(<<ERFORM);
 <input name="newsmppg" type="button" value="$lt{'sipa'}"   <form action="/adm/coursedocs" method="post" name="newext">
 onClick="javascript:makesmppage();" /> $help{'Simple Page'}   $uploadtag
 </nobr>   <input type="hidden" name="importdetail" value="" />
 </form>   <span class="LC_nobreak">
 <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">   <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 $uploadtag   value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 <input type="hidden" name="importdetail" value="" />   </span>
 <nobr>   </form>
 <input name="newsmpproblem" type="button" value="$lt{'sipr'}"  ERFORM
 onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}  
 </nobr>      if ($allowed) {
 </form>   &update_paste_buffer($coursenum,$coursedom);
 <br /><form action="/adm/coursedocs" method="post" name="newdropbox">         my %lt=&Apache::lonlocal::texthash(
 $uploadtag         'vc' => 'Verify Content',
 <input type="hidden" name="importdetail" value="" />   'cv' => 'Check/Set Resource Versions',
 <nobr>             'ls' => 'List Symbs',
 <input name="newdropbox" type="button" value="$lt{'drbx'}"                                           'sl' => 'Show Log'
 onClick="javascript:makedropbox();" />    );
 </nobr>           
 </form>          my $folderpath=$env{'form.folderpath'};
 <br /><form action="/adm/coursedocs" method="post" name="newexamupload">         if (!$folderpath) {
 $uploadtag     if ($env{'form.folder'} eq '' ||
 <input type="hidden" name="importdetail" value="" />         $env{'form.folder'} eq 'supplemental') {
 <nobr>         $folderpath='default&'.
 <input name="newexamupload" type="button" value="$lt{'scuf'}"     &escape(&mt('Main '.$type.' Documents'));
 onClick="javascript:makeexamupload();" />     }
 $help{'Score_Upload_Form'}         }
 </nobr>         unless ($env{'form.pagepath'}) {
 </form>             $containertag = '<input type="hidden" name="folderpath" value="" />';
 <br /><form action="/adm/coursedocs" method="post" name="newbul">             $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
 $uploadtag         }
 <input type="hidden" name="importdetail" value="" />         $r->print(&generate_admin_options($containertag,$uploadtag,\%lt,\%help,\%env));
 <nobr>         $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 <input name="newbulletin" type="button" value="$lt{'bull'}"       &mt('Editing the Table of Contents for your '.$type)));
 onClick="javascript:makebulboard();" />      }
 $help{'Bulletin Board'}  # --------------------------------------------------------- Standard documents
 </nobr>      $r->print('<table class="LC_docs_documents">');
 </form>  
 <br /><form action="/adm/coursedocs" method="post" name="newaboutme">      if (($standard) && ($allowed) && (!$forcesupplement)) {
 $uploadtag   $r->print('<tr><td class="LC_docs_document">');
 <input type="hidden" name="importdetail"   #  '<h2>'.&mt('Main Course Documents').
 value="$plainname=/adm/$udom/$uname/aboutme" />  #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 <nobr>         my $folder=$env{'form.folder'};
 <input name="newaboutme" type="submit" value="$lt{'mypi'}" />         if ($folder eq '' || $folder eq 'supplemental') {
 $help{'My Personal Info'}             $folder='default';
 </nobr>     $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
 </form>             $uploadtag = '<input type="hidden" name="folderpath" value="'.
 <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">         &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
 $uploadtag         }
 <input type="hidden" name="importdetail" value="" />         my $postexec='';
 <nobr>         if ($folder eq 'default') {
 <input name="newaboutsomeone" type="button" value="$lt{'abou'}"      $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
 onClick="javascript:makeabout();" />         } else {
 </nobr>             #$postexec='self.close();';
 </form>         }
 <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">         $hadchanges=0;
 $uploadtag         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,
 <input type="hidden" name="importdetail"     $upload_output,$type);
 value="Group Files=/adm/$coursedom/$coursenum/aboutme" />         if ($error) {
 <nobr>     $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />         }
 $help{'Group Files'}         if ($hadchanges) {
 </nobr>     &mark_hash_old();
 </form>         }
 ENDFORM         &changewarning($r,$postexec);
        }         my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
        if ($env{'form.pagepath'}) {                       '.sequence';
            $r->print(<<ENDBLOCK);         my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 <form action="/adm/coursedocs" method="post" name="newsmpproblem">                       '.page';
 $uploadtag   my $container='sequence';
 <input type="hidden" name="importdetail" value="" />   if ($env{'form.pagepath'}) {
 <nobr>      $container='page';
 <input name="newsmpproblem" type="button" value="$lt{'sipr'}"   }
 onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}   my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
 </nobr>  
 </form>  
 <br /><form action="/adm/coursedocs" method="post" name="newexamupload">  
 $uploadtag   my $recoverform=(<<RFORM);
 <input type="hidden" name="importdetail" value="" />   <form action="/adm/groupsort" method="post" name="recover">
 <nobr>   <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
 <input name="newexamupload" type="button" value="$lt{'scuf'}"   </form>
 onClick="javascript:makeexamupload();" />  RFORM
 $help{'Score_Upload_Form'}  
 </nobr>   my $imspform=(<<IMSPFORM);
 </form>   <form action="/adm/imsimportdocs" method="post" name="ims">
 ENDBLOCK   <input type="hidden" name="folder" value="$folder" />
        }   <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
        $r->print('</td></tr>'."\n".   </form>
 '</table>');  IMSPFORM
        $r->print('</td></tr>');  
     }   my $newnavform=(<<NNFORM);
 # ----------------------------------------------------- Supplemental documents   <form action="/adm/coursedocs" method="post" name="newnav">
     if (!$forcestandard) {   $uploadtag
        $r->print('<tr><td bgcolor="#BBBBBB">');   <input type="hidden" name="importdetail"
 # '<h2>'.&mt('Supplemental Course Documents').   value="$lt{'navc'}=/adm/navmaps" />
 #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');   <span class="LC_nobreak">
        my $folder=$env{'form.folder'};   <input name="newnav" type="submit" value="$lt{'navc'}" />
        unless ($folder=~/^supplemental/) {   $help{'Navigate_Content'}
    $folder='supplemental';   </span>
        }   </form>
        if ($folder =~ /^supplemental$/ &&  NNFORM
    $env{'form.folderpath'} =~ /^default\&/) {   my $newsmppageform=(<<NSPFORM);
    $env{'form.folderpath'}='supplemental&'.   <form action="/adm/coursedocs" method="post" name="newsmppg">
        &escape(&mt('Supplemental '.$type.' Documents'));   $uploadtag
        }   <input type="hidden" name="importdetail" value="" />
        &editor($r,$coursenum,$coursedom,$folder,$allowed);   <span class="LC_nobreak">
        if ($allowed) {   <input name="newsmppg" type="button" value="$lt{'sipa'}"
        my $folderseq=   onClick="javascript:makesmppage();" /> $help{'Simple Page'}
                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.   </span>
                      '.sequence';   </form>
   NSPFORM
           $r->print(<<ENDSUPFORM);  
 <table cellspacing=4 cellpadding=4><tr>   my $newsmpproblemform=(<<NSPROBFORM);
 <th bgcolor="#DDDDDD">$lt{'upls'}</th>   <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 <th bgcolor="#DDDDDD">$lt{'spec'}</th>   $uploadtag
 </tr>   <input type="hidden" name="importdetail" value="" />
 <tr><td bgcolor="#DDDDDD">   <span class="LC_nobreak">
 <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">   <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 <input type="file" name="uploaddoc" size="40">   onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 <br />   </span>
 <br />   </form>
 <nobr>  
 <label>$lt{'parse'}?  NSPROBFORM
 <input type="checkbox" name="parserflag" />  
 </label>   my $newdropboxform=(<<NDBFORM);
 </nobr>   <form action="/adm/coursedocs" method="post" name="newdropbox">
 <br /><br />   $uploadtag      
 $lt{'comment'}:<br />   <input type="hidden" name="importdetail" value="" />
 <textarea cols=50 rows=4 name='comment'>   <span class="LC_nobreak">          
 </textarea>   <input name="newdropbox" type="button" value="$lt{'drbx'}"
 <br />   onClick="javascript:makedropbox();" />
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   </span>        
 <input type="hidden" name="cmd" value="upload_supplemental">   </form>
 <nobr>  NDBFORM
 <input type="submit" value="$lt{'upld'}">  
  $help{'Uploading_From_Harddrive'}   my $newexuploadform=(<<NEXUFORM);
 </nobr>   <form action="/adm/coursedocs" method="post" name="newexamupload">
 </form>   $uploadtag
 </td>   <input type="hidden" name="importdetail" value="" />
 <td bgcolor="#DDDDDD">   <span class="LC_nobreak">
 <form action="/adm/coursedocs" method="post" name="supnewfolder">   <input name="newexamupload" type="button" value="$lt{'scuf'}"
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   onClick="javascript:makeexamupload();" />
 <input type="hidden" name="importdetail" value="" />   $help{'Score_Upload_Form'}
 <nobr>   </span>
 <input name="newfolder" type="button"   </form>
 onClick="javascript:makenewfolder(this.form,'$folderseq');"  NEXUFORM
 value="$lt{'newf'}" /> $help{'Adding_Folders'}  
 </nobr>   my $newbulform=(<<NBFORM);
 </form>   <form action="/adm/coursedocs" method="post" name="newbul">
 <br /><form action="/adm/coursedocs" method="post" name="supnewext">   $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="newbulletin" type="button" value="$lt{'bull'}"
 <input name="newext" type="button"    onClick="javascript:makebulboard();" />
 onClick="javascript:makenewext('supnewext');"   $help{'Bulletin Board'}
 value="$lt{'extr'}" /> $help{'Adding_External_Resource'}   </span>
 </nobr>   </form>
 </form>  NBFORM
 <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">  
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   my $newaboutmeform=(<<NAMFORM);
 <input type="hidden" name="importdetail"    <form action="/adm/coursedocs" method="post" name="newaboutme">
 value="Syllabus=/public/$coursedom/$coursenum/syllabus" />   $uploadtag
 <nobr>   <input type="hidden" name="importdetail"
 <input name="newsyl" type="submit" value="$lt{'syll'}" />   value="$plainname=/adm/$udom/$uname/aboutme" />
 $help{'Syllabus'}   <span class="LC_nobreak">
 </nobr>   <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 </form>   $help{'My Personal Info'}
 <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">   </span>
 <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />   </form>
 <input type="hidden" name="importdetail"   NAMFORM
 value="$plainname=/adm/$udom/$uname/aboutme" />  
 <nobr>   my $newaboutsomeoneform=(<<NASOFORM);
 <input name="newaboutme" type="submit" value="$lt{'mypi'}" />   <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 $help{'My Personal Info'}   $uploadtag
 </nobr>   <input type="hidden" name="importdetail" value="" />
 </form>   <span class="LC_nobreak">
 </td></tr>   <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
 </table></td></tr>   onClick="javascript:makeabout();" />
 ENDSUPFORM   </span>
        }   </form>
     }  NASOFORM
     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" /></form>');  
     }   my $newrosterform=(<<NROSTFORM);
     $r->print('</table>');   <form action="/adm/coursedocs" method="post" name="newroster">
   } else {   $uploadtag
       unless ($upload_result eq 'phasetwo') {   <input type="hidden" name="importdetail"
 # -------------------------------------------------------- This is showdoc mode   value="$lt{'rost'}=/adm/viewclasslist" />
           $r->print("<h1>".&mt('Uploaded Document').' - '.   <span class="LC_nobreak">
  &Apache::lonnet::gettitle($r->uri).'</h1><p>'.   <input name="newroster" type="submit" value="$lt{'rost'}" />
 &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".   $help{'Course Roster'}
           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');   </span>
       }   </form>
   }  NROSTFORM
  }  
  $r->print(&Apache::loncommon::end_page());         $r->print(<<ENDFORM);
  return OK;  
 }   <ul class="LC_TabContent">
   <li>$lt{'nd'}</li>
   <li>$lt{'pm'}</li>
 sub editing_js {  <li>$lt{'pubd'}</li>
     my ($udom,$uname) = @_;  <li>$lt{'sd'}</li>
     my $now = time();  <li>$lt{'mo'}</li>
   <li>$lt{'hao'}</li>
     return <<ENDNEWSCRIPT;  </ul>
 function makenewfolder(targetform,folderseq) {  
     var foldername=prompt('Name of New Folder','New Folder');  <table class="LC_docs_adddocs">
     if (foldername) {  <!-- <tr>
        targetform.importdetail.value=escape(foldername)+"="+folderseq;  <th>$lt{'uplm'}</th>
         targetform.submit();  <th>$lt{'impp'}</th>
     }  <th>$lt{'spec'}</th>
 }  </tr> -->
   <tr>
 function makenewpage(targetform,folderseq) {  <td>
     var pagename=prompt('Name of New Page','New Page');  $fileuploadform
     if (pagename) {  </td>
         targetform.importdetail.value=escape(pagename)+"="+folderseq;  <td>
         targetform.submit();  $simpleeditdefaultform
     }  <hr />
 }  $recoverform
   ENDFORM
 function makenewext(targetname) {         unless ($env{'form.pagepath'}) {
     this.document.forms.extimport.useform.value=targetname;     $r->print(<<ENDFORM);
     window.open('/adm/rat/extpickframe.html');  <hr />
 }  $extresourcesform
    <br />
 function makeexamupload() {  $imspform
    var title=prompt('Listed Title for the Uploaded Score');  ENDFORM
    if (title) {          }
     this.document.forms.newexamupload.importdetail.value=         $r->print('</td><td>');
  escape(title)+'=/res/lib/templates/examupload.problem';         unless ($env{'form.pagepath'}) {
     this.document.forms.newexamupload.submit();     my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
    }  
 }  
   
 function makesmppage() {   my $newpageform=(<<NPFORM);
    var title=prompt('Listed Title for the Page');   <form action="/adm/coursedocs" method="post" name="newpage">
    if (title) {    <input type="hidden" name="folderpath" value="$path" />
     this.document.forms.newsmppg.importdetail.value=   <input type="hidden" name="importdetail" value="" />
  escape(title)+'=/adm/$udom/$uname/$now/smppg';   <span class="LC_nobreak">
     this.document.forms.newsmppg.submit();   <input name="newpage" type="button"
    }   onClick="javascript:makenewpage(this.form,'$pageseq');"
 }   value="$lt{'newp'}" />$help{'Adding_Pages'}
    </span>
 function makesmpproblem() {   </form>
    var title=prompt('Listed Title for the Problem');  NPFORM
    if (title) {   
     this.document.forms.newsmpproblem.importdetail.value=   my $newfolderform=(<<NFFORM);
  escape(title)+'=/res/lib/templates/simpleproblem.problem';   <form action="/adm/coursedocs" method="post" name="newfolder">
     this.document.forms.newsmpproblem.submit();   <input type="hidden" name="folderpath" value="$path" />
    }   <input type="hidden" name="importdetail" value="" />
 }   <span class="LC_nobreak">
    <input name="newfolder" type="button"
 function makedropbox() {   onClick="javascript:makenewfolder(this.form,'$folderseq');"
    var title=prompt('Listed Title for the Drop Box');   value="$lt{'newf'}" />$help{'Adding_Folders'}
    if (title) {    </span>
     this.document.forms.newdropbox.importdetail.value=   </form>
         escape(title)+'=/res/lib/templates/DropBox.problem';  NFFORM
     this.document.forms.newdropbox.submit();  
    }   my $newsylform=(<<NSYLFORM);
 }   <form action="/adm/coursedocs" method="post" name="newsyl">
    $uploadtag
 function makebulboard() {   <input type="hidden" name="importdetail"
    var title=prompt('Listed Title for the Bulletin Board');   value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
    if (title) {   <span class="LC_nobreak">
     this.document.forms.newbul.importdetail.value=   <input name="newsyl" type="submit" value="$lt{'syll'}" />
  escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';   $help{'Syllabus'}
     this.document.forms.newbul.submit();   </span>
    }   </form>
 }  NSYLFORM
   
 function makeabout() {   my $newgroupfileform=(<<NGFFORM);
    var user=prompt("Enter user:domain for User's 'About Me' Page");   <form action="/adm/coursedocs" method="post" name="newgroupfiles">
    if (user) {   $uploadtag
        var comp=new Array();   <input type="hidden" name="importdetail"
        comp=user.split(':');   value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {   <span class="LC_nobreak">
    if ((comp[0]) && (comp[1])) {   <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
        this.document.forms.newaboutsomeone.importdetail.value=   $help{'Group Files'}
    'About '+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';   </span>
        this.document.forms.newaboutsomeone.submit();   </form>
    } else {  NGFFORM
                alert("Not a valid user:domain");  
            }  
        } else {             $r->print(<<ENDFORM);
            alert("Please enter both user and domain in the format user:domain");   <br />
        }  $newfolderform
    }  <br />
 }  $newpageform
   <br />
 function makeims() {  $newsylform
     var caller = document.forms.ims.folder.value;  <br />
     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";  $newnavform
     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");  <br />
     newWindow.location.href = newlocation;  $newsmppageform
 }  <br />
   $newsmpproblemform
   <br />
 function finishpick() {  $newdropboxform
     var title=this.document.forms.extimport.title.value;  <br />
     var url=this.document.forms.extimport.url.value;  $newexuploadform
     var form=this.document.forms.extimport.useform.value;  <br />
     eval  $newbulform
      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+  <br />
     '";this.document.forms.'+form+'.submit();');  $newaboutmeform
 }  <br />
   $newaboutsomeoneform
 function changename(folderpath,index,oldtitle,container,pagesymb) {  <br />
     var title=prompt('New Title',oldtitle);  $newgroupfileform
     if (title) {  <br />
  this.document.forms.renameform.title.value=title;  $newrosterform
  this.document.forms.renameform.cmd.value='rename_'+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 removeres(folderpath,index,oldtitle,container,pagesymb) {      }
     if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {  # ----------------------------------------------------- Supplemental documents
  this.document.forms.renameform.cmd.value='del_'+index;      if (!$forcestandard) {
         if (container == 'sequence') {         $r->print('<tr><td class="LC_docs_document">');
             this.document.forms.renameform.folderpath.value=folderpath;  # '<h2>'.&mt('Supplemental Course Documents').
         }  #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
         if (container == 'page') {         my $folder=$env{'form.folder'};
             this.document.forms.renameform.pagepath.value=folderpath;         unless ($folder=~/^supplemental/) {
             this.document.forms.renameform.pagesymb.value=pagesymb;     $folder='supplemental';
         }         }
         this.document.forms.renameform.submit();         if ($folder =~ /^supplemental$/ &&
     }     (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
 }            $env{'form.folderpath'} = 'supplemental&'.
                                       &escape(&mt('Supplemental '.$type.' Documents'));
 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+'"?')) {         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
  this.document.forms.renameform.cmd.value='cut_'+index;         if ($error) {
  this.document.forms.renameform.markcopy.value=index;     $r->print('<p><span class="LC_error">'.$error.'</span></p>');
         if (container == 'sequence') {         }
             this.document.forms.renameform.folderpath.value=folderpath;         if ($allowed) {
         }     my $folderseq=
         if (container == 'page') {         '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
             this.document.forms.renameform.pagepath.value=folderpath;         '.sequence';
             this.document.forms.renameform.pagesymb.value=pagesymb;  
         }     my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
         this.document.forms.renameform.submit();  
     }   my $supupdocform=(<<SUPDOCFORM);
 }   <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
    $fileupload
 function markcopy(folderpath,index,oldtitle,container,pagesymb) {   <br />
     this.document.forms.renameform.markcopy.value=index;   <br />
     if (container == 'sequence') {   <span class="LC_nobreak">
  this.document.forms.renameform.folderpath.value=folderpath;   $checkbox
     }   </span>
     if (container == 'page') {   <br /><br />
  this.document.forms.renameform.pagepath.value=folderpath;   $lt{'comment'}:<br />
  this.document.forms.renameform.pagesymb.value=pagesymb;   <textarea cols=50 rows=4 name='comment'>
     }   </textarea>
     this.document.forms.renameform.submit();   <br />
 }   <input type="hidden" name="folderpath" value="$path" />
    <input type="hidden" name="cmd" value="upload_supplemental" />
 ENDNEWSCRIPT   <span class="LC_nobreak">
 }   <input type="submit" value="$lt{'upld'}" />
 1;   $help{'Uploading_From_Harddrive'}
 __END__   </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.275  
changed lines
  Added in v.1.328


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