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

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


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