Diff for /loncom/interface/groupsort.pm between versions 1.62 and 1.75

version 1.62, 2008/09/15 13:22:48 version 1.75, 2016/11/22 13:51:29
Line 32  package Apache::groupsort; Line 32  package Apache::groupsort;
   
 use strict;  use strict;
   
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common :http);
 use GDBM_File;  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 59  sub update_actions_hash { Line 59  sub update_actions_hash {
  $ac++;   $ac++;
     }      }
     # 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'};
Line 86  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 152  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 181  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']);
   
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
   
   # permissions checking
       my ($allowed,$canedit,$context,$cid);
       if ($env{'form.readfile'} =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
           my ($cdom,$cnum) = ($1,$2);
           $cid = $cdom.'_'.$cnum;
           $context = 'course';
           if ((&Apache::lonnet::allowed('mdc',$cid)) ||
               (&Apache::lonnet::allowed('cev',$cid))) {
               $allowed = 1;
           }
       } elsif ($env{'form.readfile'} =~ m{^/res/}) {
           $context = 'res';
           if ((&Apache::lonnet::allowed('bre',$env{'form.readfile'})) ||
               (&Apache::lonnet::allowed('bro',$env{'form.readfile'}))) {
               $allowed = 1;
           }
       } elsif (($env{'form.readfile'} eq '') && ($env{'form.acts'} ne '')) {
           $allowed = 1;
       }
       if ($allowed) {
           if ($env{'form.mode'} eq 'rat') {
               if (&Apache::lonnet::allowed('are',$env{'request.role.domain'})) {
                   $canedit = 1;
               }
           } elsif (($env{'form.mode'} eq 'simple') || ($env{'form.mode'} eq '')) {
               if ($context eq 'course') {
                   if (&Apache::lonnet::allowed('mdc',$cid)) {
                       $canedit = 1;
                   }
               } elsif (($env{'request.course.id'}) &&
                        (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
                   $canedit = 1;
               } elsif (&Apache::lonnet::allowed('are',$env{'request.role.domain'})) {
                   $canedit = 1;
               }
           }
       }
   
       unless ($allowed) {
           if ($context eq 'course') {
               if ($env{'request.course.id'} eq $cid) { 
                   $env{'user.error.msg'}=
                       "/adm/groupsort::0:1:Course environment gone, reinitialize the course";
               } else {
                   $env{'user.error.msg'}=
                       "/adm/groupsort:bre:0:0:Cannot view folder contents";
               }
           } else {
               $env{'user.error.msg'}=
                   "/adm/groupsort:bre:0:0:Cannot view map contents";
           }
           return HTTP_NOT_ACCEPTABLE;
       }
   
 # finish_import looks different for graphical or "simple" RAT  # finish_import looks different for graphical or "simple" RAT
     my $finishimport='';      my $finishimport='';
     my $begincondition='';      my $begincondition='';
     my $endcondition='';      my $endcondition='';
     if (($env{'form.readfile'}) || ($env{'form.bookmarks'}))  {      my $noedit;
       unless ($canedit) {
           if ($context eq 'course') {
               $noedit = &js_escape(&mt('You do not have rights to edit the course.'));
           } else {
               $noedit = &js_escape(&mt('You do not have rights to edit map contents.'));
           }
       } 
       if (($env{'form.readfile'}))  {
         $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';          $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
  $endcondition='}';   $endcondition='}';
     }      }
     if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {      if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {
         $finishimport=(<<ENDSMP);          if ($canedit) {
               $finishimport=(<<ENDSMP);
 function finish_import() {  function finish_import() {
     opener.document.forms.simpleedit.importdetail.value='';      opener.document.forms.simpleedit.importdetail.value='';
     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {      for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
Line 235  function finish_import() { Line 290  function finish_import() {
     self.close();      self.close();
 }  }
 ENDSMP  ENDSMP
           } else {
               $finishimport=(<<ENDNO);
   function finish_import() {
       alert('$noedit');
   } 
   ENDNO
           }
     } else {      } else {
         $finishimport=(<<ENDADV);          if ($canedit) {
               $finishimport=(<<ENDADV);
 function finish_import() {  function finish_import() {
     var linkflag=false;      var linkflag=false;
     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {      for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
Line 258  function finish_import() { Line 321  function finish_import() {
     self.close();      self.close();
 }  }
 ENDADV  ENDADV
           } else {
               $finishimport=(<<ENDNONE);
   function finish_import() {
       alert('$noedit');
   }
   ENDNONE
           }
     }      }
   
 # output start of web page  # output start of web page
Line 299  END Line 369  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';
       }
       my $disabled;
       unless ($canedit) {
           $disabled = ' disabled="disabled"';
       }
       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 332  END Line 411  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()"$disabled />&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
  } else {   } else {
         # --- Continue Buttons          # --- Continue Buttons
Line 353  END Line 432  END
 <h2>$lt{'fin'}</h2>  <h2>$lt{'fin'}</h2>
 <div>  <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'}"
  onClick="window.location='/adm/searchcat?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;   onclick="window.location='/adm/searchcat?inhibitmenu=yes&amp;catalogmode=import'" />&nbsp;
 <input type="button" name="alter" value="$lt{'fi'}"  <input type="button" name="alter" value="$lt{'fi'}"
  onClick="finish_import()" />&nbsp;   onclick="finish_import()"$disabled />&nbsp;
 <input type="button" name="alter" value="$lt{'ca'}" onClick="self.close()" />  <input type="button" name="alter" value="$lt{'ca'}" onclick="self.close()" />
 </div>  </div>
 <br />  <br />
 END  END
         }          }
         $r->print(&Apache::loncommon::start_data_table()  
                  .&Apache::loncommon::start_data_table_header_row());          # Only display header if content exists
  if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {           if ($clen > 0) {
     $r->print("<th>$lt{'in'}</th>\n");              $r->print(&Apache::loncommon::start_data_table()
  } else {                        .&Apache::loncommon::start_data_table_header_row());
     $r->print("<th colspan='2'>$lt{'co'}</th>\n");               if (($env{'form.readfile'})) { 
  }                  $r->print("<th>$lt{'in'}</th>\n");
  $r->print("<th colspan='2'>$lt{'ti'}</th>\n");              } else { 
  $r->print("<th>$lt{'pa'}</th>");                  $r->print('<th colspan="2">'.$lt{'co'}.'</th>'."\n"); 
         $r->print(&Apache::loncommon::end_data_table_header_row()              }
                  ."\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 391  END Line 482  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(&Apache::loncommon::start_data_table_row()      $r->print(&Apache::loncommon::start_data_table_row()
                      ."<td>");                       ."<td>");
             if (($env{'form.readfile'}) || ($env{'form.bookmarks'})) {              if (($env{'form.readfile'})) {
  $r->print(&checkbox($ctr-1));   $r->print(&checkbox($ctr-1,$disabled));
     } else {      } else {
  $r->print(&movers($clen,$ctr));   $r->print(&movers($clen,$ctr));
     }      }
  }   }
  $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>".   $r->print("<td>".
   &select_box($clen,$ctr).    &select_box($clen,$ctr,$disabled).
   "</td>");    "</td>");
     }      }
     $r->print("<td>");      $r->print("<td>");
     $r->print("<img src='$iconname' />");      $r->print("<img src='$iconname' />");
     $r->print("</td><td>");      $r->print("</td><td>");
     $r->print($resource->{'title'}.$resource->{'notes'}."</td><td>\n");              if (($env{'form.recover'}) &&
                   ($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>"      $r->print($resource->{'url'}."</td>"
                      .&Apache::loncommon::end_data_table_row()                       .&Apache::loncommon::end_data_table_row()
                      ."\n");                       ."\n");
  }    } 
     }      }
     if (($clen > 1) || ($env{'form.readfile'}) || ($env{'form.bookmarks'})) {      if (($clen > 1) || ($env{'form.readfile'})) {
         $r->print(&Apache::loncommon::end_data_table()          if ($clen > 0) {
                  ."</form>");              $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 467  END Line 567  END
   
 # ------------------------------------------ Select box (returns scalar string)  # ------------------------------------------ Select box (returns scalar string)
 sub select_box {  sub select_box {
     my ($total,$sel) = @_;      my ($total,$sel,$disabled) = @_;
     my $string;      my $string;
     $string = '<select name="alt'.$sel.'"';      $string = '<select name="alt'.$sel.'"';
     $string .= " onChange='selectchange($sel)'>";      $string .= " onchange='selectchange($sel)'.$disabled.'>";
     $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";      $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";
     for my $cur (1..$total) {      for my $cur (1..$total) {
  $string .= "<option name='o$cur' value='$cur'";   $string .= "<option name='o$cur' value='$cur'";
Line 486  sub select_box { Line 586  sub select_box {
 # ------------------------------------------------------------------- Checkbox  # ------------------------------------------------------------------- Checkbox
   
 sub checkbox {  sub checkbox {
     my $sel=shift;      my ($sel,$disabled) = @_;
     return "<label><input type='checkbox' name='include$sel'".      return "<label><input type='checkbox' name='include$sel'".
        ($env{"form.include$sel"}?' checked="checked"':'').         ($env{"form.include$sel"}?' checked="checked"':'').
        ' />'.&mt('Include').'</label>';         $disabled.' />'.&mt('Include').'</label>';
 }  }
   
 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.62  
changed lines
  Added in v.1.75


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.