Diff for /loncom/interface/groupsort.pm between versions 1.59 and 1.71

version 1.59, 2007/07/12 19:54:43 version 1.71, 2013/01/09 03:56:28
Line 37  use GDBM_File; Line 37  use GDBM_File;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use LONCAPA();  use LONCAPA qw(:DEFAULT :match);
   
 my $iconpath; # variable to be accessible to multiple subroutines  my $iconpath; # variable to be accessible to multiple subroutines
 my %hash; # variable to tie to user specific database  my %hash; # variable to tie to user specific database
Line 45  my %hash; # variable to tie to user spec Line 45  my %hash; # variable to tie to user spec
   
 sub update_actions_hash {  sub update_actions_hash {
     my ($hash) = @_;      my ($hash) = @_;
       # be careful in here, there is also a global %hash
     my $acts=$env{'form.acts'};      my $acts=$env{'form.acts'};
     my @Acts=split(/b/,$acts);      my @Acts=split(/b/,$acts);
     my %ahash;      my %ahash;
     my %achash;      my %achash;
     my $ac=0;  
     # some initial hashes for working with data      # some initial hashes for working with data
       my $ac=0;
     foreach (@Acts) {      foreach (@Acts) {
  my ($state,$ref)=split(/a/);    my ($state,$ref)=split(/a/);
  $ahash{$ref}=$state;   $ahash{$ref}=$state;
  $achash{$ref}=$ac;   $achash{$ref}=$ac;
  $ac++;   $ac++;
Line 60  sub update_actions_hash { Line 61  sub update_actions_hash {
     # sorting through the actions and changing the global database hash      # sorting through the actions and changing the global database hash
     foreach my $key (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {      foreach my $key (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
  if ($ahash{$key} eq '1') {   if ($ahash{$key} eq '1') {
     $hash->{'store_'.$hash{'pre_'.$key.'_link'}}=      $hash->{'store_'.$hash->{'pre_'.$key.'_link'}}=
  $hash->{'pre_'.$key.'_title'};   $hash->{'pre_'.$key.'_title'};
     $hash->{'storectr_'.$hash{'pre_'.$key.'_link'}}=      $hash->{'storectr_'.$hash->{'pre_'.$key.'_link'}}=
  $hash->{'storectr'}+0;   $hash->{'storectr'}+0;
     $hash->{'storectr'}++;      $hash->{'storectr'}++;
  }   }
  if ($ahash{$key} eq '0') {   if ($ahash{$key} eq '0') {
     if ($hash->{'store_'.$hash{'pre_'.$key.'_link'}}) {      if ($hash->{'store_'.$hash->{'pre_'.$key.'_link'}}) {
  delete($hash->{'store_'.$hash{'pre_'.$key.'_link'}});   delete($hash->{'store_'.$hash->{'pre_'.$key.'_link'}});
    delete($hash->{'storectr_'.$hash->{'pre_'.$key.'_link'}});
     }      }
  }   }
     }      }
Line 84  sub update_actions_hash { Line 86  sub update_actions_hash {
 sub readfromdb {  sub readfromdb {
     my ($r,$resources)=@_;      my ($r,$resources)=@_;
   
     my $diropendb =       my $diropendb = LONCAPA::tempdir() .
        "/home/httpd/perl/tmp/$env{'user.domain'}_$env{'user.name'}_sel_res.db";         "$env{'user.domain'}_$env{'user.name'}_sel_res.db";
   
 # ----------------------------- diropendb is now the filename of the db to open  # ----------------------------- diropendb is now the filename of the db to open
     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {      if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
Line 150  sub readfromfile { Line 152  sub readfromfile {
   &Apache::lonnet::filelocation('',$env{'form.readfile'}));    &Apache::lonnet::filelocation('',$env{'form.readfile'}));
     } else {      } else {
         my $parser = HTML::TokeParser->new(\$cont);          my $parser = HTML::TokeParser->new(\$cont);
         my $token;          my ($token,$donechk,$allmaps);
           $allmaps = {};
         while ($token = $parser->get_token) {          while ($token = $parser->get_token) {
     if ($token->[0] eq 'S') {      if ($token->[0] eq 'S') {
                 if ($token->[1] eq 'resource') {                  if ($token->[1] eq 'resource') {
     if ($env{'form.recover'}) {      if ($env{'form.recover'}) {
  if ($token->[2]->{'type'} ne 'zombie') { next; }   if ($token->[2]->{'type'} ne 'zombie') { next; }
                           if ($token->[2]->{'src'} =~ /\.(page|sequence)$/) {
                               if (($env{'request.course.id'}) &&
                                   ($env{'form.readfile'} =~ m{/default(|_\d+)\.(page|sequence)$})) {
                                   unless ($donechk) {
                                       $allmaps = &Apache::loncommon::allmaps_incourse();
                                       $donechk = 1;
                                   }
                               }
                               if ($allmaps->{$token->[2]->{'src'}}) { next; }
                           }
     } else {      } else {
  if ($token->[2]->{'type'} eq 'zombie') { next; }   if ($token->[2]->{'type'} eq 'zombie') { next; }
     }      }
Line 179  sub readfromfile { Line 192  sub readfromfile {
     }      }
 }  }
   
 # --------------------------------------------------------- Read from bookmarks  
   
 sub readfrombookmarks {  
     my ($r,$resources)=@_;  
     my %bookmarks=&Apache::lonnet::dump('bookmarks');  
 # the bookmark "hash" is just one entry  
 # it's a javascript program code with arguments like ('title','url');  
     my @bookmarks=($bookmarks{'bookmarks'}=~/\((?:\'([^\']+)\'\,\'([^\']+)\'|\"([^\"]+)\"\,\"([^\"]+)\")\)\;/g);  
     for (my $index=0;$index<($#bookmarks+1)/2;$index++) {  
         if ($bookmarks[$index*2+1]) {  
     my $url  = $bookmarks[$index*2+1];  
     my $name = $bookmarks[$index*2];  
     $name =~ s/^LON\-CAPA\s+//;  
   
     push(@{$resources},{'url' => $url, 'title' => $name});  
  }  
     }  
 }  
   
 # ---------------------------------------------------------------- Main Handler  # ---------------------------------------------------------------- Main Handler
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
      ['acts','mode','readfile','recover','bookmarks']);       ['acts','mode','readfile','recover']);
     # color scheme  
     my $fileclr = '#ffffe6';  
     my $titleclr = '#ddffff';  
   
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
Line 216  sub handler { Line 207  sub handler {
     my $finishimport='';      my $finishimport='';
     my $begincondition='';      my $begincondition='';
     my $endcondition='';      my $endcondition='';
     if (($env{'form.readfile'}) || ($env{'form.bookmarks'}))  {      if (($env{'form.readfile'}))  {
         $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';          $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
  $endcondition='}';   $endcondition='}';
     }      }
Line 227  function finish_import() { Line 218  function finish_import() {
     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {      for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
  $begincondition   $begincondition
  opener.document.forms.simpleedit.importdetail.value+='&'+   opener.document.forms.simpleedit.importdetail.value+='&'+
               escape(eval("document.forms.groupsort.title"+num+".value"))+'='+                eval("document.forms.groupsort.title"+num+".value")+'='+
       escape(eval("document.forms.groupsort.filelink"+num+".value"))+'='+        eval("document.forms.groupsort.filelink"+num+".value")+'='+
       escape(eval("document.forms.groupsort.id"+num+".value"));        eval("document.forms.groupsort.id"+num+".value");
  $endcondition   $endcondition
     }      }
     opener.document.forms.simpleedit.submit();      opener.document.forms.simpleedit.submit();
Line 300  END Line 291  END
   
     if ($env{'form.readfile'}) {      if ($env{'form.readfile'}) {
  &readfromfile($r,\@resources);   &readfromfile($r,\@resources);
     } elsif ($env{'form.bookmarks'}) {  
  &readfrombookmarks($r,\@resources);  
     } else {      } else {
  &readfromdb($r,\@resources);   &readfromdb($r,\@resources);
     }      }
   
     my $ctr = 0;      my $ctr = 0;
     my $clen = scalar(@resources);      my $clen = scalar(@resources);
     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {      my $title = '';
       if ($env{'form.recover'}) {
           $title = 'Recover Removed Resources';
       } else {
           $title = 'Sort Imported Resources';
       }
       if (($clen > 1) || ($env{'form.readfile'})) {
  my %lt=&Apache::lonlocal::texthash(   my %lt=&Apache::lonlocal::texthash(
  'fin'=> 'Finalize order of resources',   'fin'=> 'Finalize order of resources',
  'ci' => 'Continue Import',   'ci' => 'Continue Import',
  'cs' => 'Continue Search',   'cs' => 'Continue Search',
  'fi' => 'Finish Import',   'fi' => 'Finish Import',
  're' => 'Recover Checked',   're' => 'Recover Checked',
    'ip' => 'Import Checked',
  'ca' => 'Cancel',   'ca' => 'Cancel',
  'co' => 'Change Order',   'co' => 'Change Order',
  'ti' => 'Title',   'ti' => 'Title',
  'pa' => 'Path',   'pa' => 'Path',
                 'in' => 'Include'                  'in' => 'Include'
  );   );
  my $title = ($env{'form.recover'}) ? 'Recover Removed Resources'  
                                            : 'Sort Imported Resources';  
  $r->print(&Apache::loncommon::start_page($title, $js));   $r->print(&Apache::loncommon::start_page($title, $js));
    $r->print('<h1>'.&mt($title).'</h1>');
   
  $r->print(<<END);   $r->print(<<END);
 <form method='post' action='/adm/groupsort' name='groupsort'  <form method='post' action='/adm/groupsort' name='groupsort'
Line 333  END Line 329  END
 <input type="hidden" name="newval" value="" />  <input type="hidden" name="newval" value="" />
 <input type="hidden" name="mode" value="$env{'form.mode'}" />  <input type="hidden" name="mode" value="$env{'form.mode'}" />
 <input type="hidden" name="readfile" value="$env{'form.readfile'}" />  <input type="hidden" name="readfile" value="$env{'form.readfile'}" />
 <input type="hidden" name="bookmarks" value="$env{'form.bookmarks'}" />  
 <input type="hidden" name="recover" value="$env{'form.recover'}" />  <input type="hidden" name="recover" value="$env{'form.recover'}" />
 END  END
   
         $r->print(&Apache::loncommon::inhibit_menu_check('input'));          $r->print(&Apache::loncommon::inhibit_menu_check('input'));
         # ---          # ---
       
           my $buttontext = $lt{'re'};
         if ($env{'form.recover'}) {          if ($env{'form.recover'}) {
     $r->print(<<END);      $r->print(<<END);
 <input type="button" name="alter" value="$lt{'re'}"  <input type="button" name="alter" value="$buttontext"
  onClick="finish_import()" />&nbsp;   onClick="finish_import()" />&nbsp;
 <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />  <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
 END  END
Line 351  END Line 347  END
     my $resurl =       my $resurl = 
  &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());   &Apache::loncommon::escape_single(&Apache::loncommon::lastresurl());
     $r->print(<<END);      $r->print(<<END);
 <b><font color="#888888">$lt{'fin'}</font></b>  <h2>$lt{'fin'}</h2>
   <div>
 <input type="button" name="alter" value="$lt{'ci'}"  <input type="button" name="alter" value="$lt{'ci'}"
  onClick="window.location='$resurl?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;   onClick="window.location='$resurl?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
 <input type="button" name="altersearch" value="$lt{'cs'}"  <input type="button" name="altersearch" value="$lt{'cs'}"
Line 359  END Line 356  END
 <input type="button" name="alter" value="$lt{'fi'}"  <input type="button" name="alter" value="$lt{'fi'}"
  onClick="finish_import()" />&nbsp;   onClick="finish_import()" />&nbsp;
 <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />  <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />
   </div>
   <br />
 END  END
         }          }
         $r->print("<table border='0'><tr><td bgcolor='#eeeeee'>");  
  $r->print("<table border=0><tr>\n");          # Only display header if content exists
  if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {           if ($clen > 0) {
     $r->print("<td bgcolor='$titleclr'><b>$lt{'in'}</b></td>\n");              $r->print(&Apache::loncommon::start_data_table()
  } else {                        .&Apache::loncommon::start_data_table_header_row());
     $r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'co'}</b></td>\n");               if (($env{'form.readfile'})) { 
  }                  $r->print("<th>$lt{'in'}</th>\n");
  $r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'ti'}</b></td>\n");              } else { 
  $r->print("<td bgcolor='$titleclr'><b>$lt{'pa'}</b></td></tr>\n");                  $r->print('<th colspan="2">'.$lt{'co'}.'</th>'."\n"); 
               }
               $r->print('<th colspan="2">'.$lt{'ti'}.'</th>'."\n");
               $r->print("<th>$lt{'pa'}</th>");
               $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
           } else {
               my $errtxt = '';
               if ($env{'form.recover'}) {
                   $errtxt = 'There are no resources to recover.';
               } else {
                   $errtxt = 'There are no resources to import.';
               }
               $r->print('<p class="LC_info">'.&mt($errtxt).'</p>');
           }
     } else {      } else {
  $r->print(&Apache::loncommon::start_page(undef,$js,   $r->print(&Apache::loncommon::start_page(undef,$js,
  {'only_body' => 1}));   {'only_body' => 1}));
   #       $r->print('<h1>'.&mt($title).'</h1>');
  $r->print(<<END);   $r->print(<<END);
 <form method='post' action='/adm/groupsort' name='groupsort'  <form method='post' action='/adm/groupsort' name='groupsort'
       enctype='application/x-www-form-urlencoded'>        enctype='application/x-www-form-urlencoded'>
Line 387  END Line 400  END
     foreach my $resource (@resources) {      foreach my $resource (@resources) {
  $ctr++;   $ctr++;
  my $iconname=&Apache::loncommon::icon($resource->{'url'});   my $iconname=&Apache::loncommon::icon($resource->{'url'});
  if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {   if (($clen > 1) || ($env{'form.readfile'})) {
     $r->print("<tr><td bgcolor='$fileclr'>");      $r->print(&Apache::loncommon::start_data_table_row()
             if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {                       ."<td>");
               if (($env{'form.readfile'})) {
  $r->print(&checkbox($ctr-1));   $r->print(&checkbox($ctr-1));
     } else {      } else {
  $r->print(&movers($clen,$ctr));   $r->print(&movers($clen,$ctr));
Line 397  END Line 411  END
  }   }
  $r->print(&hidden($ctr-1,$resource->{'title'},$resource->{'url'},   $r->print(&hidden($ctr-1,$resource->{'title'},$resource->{'url'},
   $resource->{'id'}));    $resource->{'id'}));
  if (($clen > 1)  || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {   if (($clen > 1)  || ($env{'form.readfile'})) {
     $r->print("</td>");      $r->print("</td>");
             unless (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {              unless (($env{'form.readfile'})) {
  $r->print("<td bgcolor='$fileclr'>".   $r->print("<td>".
   &select_box($clen,$ctr).    &select_box($clen,$ctr).
   "</td>");    "</td>");
     }      }
     $r->print("<td bgcolor='$fileclr'>");      $r->print("<td>");
     $r->print("<img src='$iconname' />");      $r->print("<img src='$iconname' />");
     $r->print("</td><td bgcolor='$fileclr'>");      $r->print("</td><td>");
     $r->print($resource->{'title'}.$resource->{'notes'}."</td><td bgcolor='$fileclr'>\n");              if (($env{'form.recover'}) && 
     $r->print($resource->{'url'}."</td></tr>\n");                  ($resource->{'url'} =~ m{/uploaded/$match_domain/$match_courseid/supplemental/})) {
           my $title = &Apache::loncommon::parse_supplemental_title($resource->{'title'});
                   $r->print($title);
               } else {
                    $r->print($resource->{'title'});
               }
               $r->print($resource->{'notes'}."</td><td>\n");
       $r->print($resource->{'url'}."</td>"
                        .&Apache::loncommon::end_data_table_row()
                        ."\n");
  }    } 
     }      }
     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {      if (($clen > 1) || ($env{'form.readfile'})) {
  $r->print("</table></td></tr></table></form>");          if ($clen > 0) {
               $r->print(&Apache::loncommon::end_data_table());
           }
           $r->print('</form>');
     } else {      } else {
  $r->print(<<END);   $r->print(<<END);
 <script type="text/javascript">  <script type="text/javascript">
Line 429  END Line 455  END
 # --------------------------------------- Hidden values (returns scalar string)  # --------------------------------------- Hidden values (returns scalar string)
 sub hidden {  sub hidden {
     my ($sel,$title,$filelink,$id) = @_;      my ($sel,$title,$filelink,$id) = @_;
     my $string = '<input type="hidden" name="title'.$sel.'" value="'.$title.      my $string = '<input type="hidden" name="title'.$sel.'" value="'.
  '" />';   &escape($title).'" />';
     $filelink=~s|^/ext/|http://|;      $filelink=~s|^/ext/|http://|;
     $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.      $string .= '<input type="hidden" name="filelink'.$sel.'" value="'.
  $filelink.'" />';   &escape($filelink).'" />';
     $string .= '<input type="hidden" name="id'.$sel.'" value="'.$id.'" />';      $string .= '<input type="hidden" name="id'.$sel.'" value="'.&escape($id).'" />';
     return $string;      return $string;
 }  }
   
Line 487  sub checkbox { Line 513  sub checkbox {
 1;  1;
   
 __END__  __END__
   
   =pod
   
   =head1 NAME
   
   Apache::groupsort.pm
   
   =head1 SYNOPSIS
   
   Implements a second phase of importing
   multiple resources into the RAT. Allows for
   reordering the sequence of resources
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   
   =head1 NOTABLE SUBROUTINES
   
   =over
   
   =item 
   
   =back
   
   =cut
   

Removed from v.1.59  
changed lines
  Added in v.1.71


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