Diff for /loncom/interface/londocs.pm between versions 1.643 and 1.651

version 1.643, 2017/11/30 02:17:50 version 1.651, 2018/01/12 13:33:37
Line 45  use Apache::lontemplate(); Line 45  use Apache::lontemplate();
 use Apache::lonsimplepage();  use Apache::lonsimplepage();
 use Apache::lonhomework();  use Apache::lonhomework();
 use Apache::lonpublisher();  use Apache::lonpublisher();
   use Apache::lonparmset();
   use Apache::loncourserespicker();
 use HTML::Entities;  use HTML::Entities;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
Line 670  sub group_import { Line 672  sub group_import {
                 }                  }
                 $toolid =~ s/\D//g;                  $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},                  ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
                  $toolhash{'linktext'},$toolhash{'explanation'},                   $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                  $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;                   $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
                 foreach my $item (@extras) {                  foreach my $item (@extras) {
                     $toolhash{$item} = &unescape($toolhash{$item});                      $toolhash{$item} = &unescape($toolhash{$item});
                 }                  }
                   if ($folder =~ /^supplemental/) {
                       delete($toolhash{'gradable'});
                   } else {
                       $toolhash{'gradable'} =~ s/\D+//g;
                   }
                 if (ref($ltitoolsref) eq 'HASH') {                  if (ref($ltitoolsref) eq 'HASH') {
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {                      if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
                         my @deleted;                          my @deleted;
Line 762  sub group_import { Line 769  sub group_import {
                             $toolhash{'rostersecret'} = $rostersecret;                              $toolhash{'rostersecret'} = $rostersecret;
                             $toolhash{'rostersecretdate'} = time;                              $toolhash{'rostersecretdate'} = time;
                         }                          }
                           my $changegradable;
                           if (($residx) && ($folder =~ /^default/)) {
                               if ($toolsettings{'gradable'}) {
                                   unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                                       push(@deleted,'gradable');
                                       $changegradable = 1;
                                   }
                               } elsif ($toolhash{'gradable'}) {
                                   $changegradable = 1;
                               }
                               if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
                                   $changegradable = 1;
                                   if ($toolsettings{'gradable'}) {
                                       $toolhash{'gradable'} = 1;
                                   }
                               }
                           }
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);                          my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                         if ($putres eq 'ok') {                          if ($putres eq 'ok') {
                             if (@deleted) {                              if (@deleted) {
                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);                                  &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
                             }                               }
                               if (($changegradable) && ($folder =~ /^default/)) {
                                   my $val;
                                   if ($toolhash{'gradable'}) {
                                       $val = 'yes';
                                   } else {
                                       $val = 'no';
                                   }
                                   &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                                                                 'string_yesno');
                                   &remember_parms($residx,'gradable','set',$val);
                               }
                           } else {
                               return (&mt('Failed to save update to external tool.'),1);
                         }                          }
                     }                      }
                 }                  }
Line 1004  sub docs_change_log { Line 1041  sub docs_change_log {
     'encrypturl'     => 'URL hidden',      'encrypturl'     => 'URL hidden',
     'randompick'     => 'Randomly pick',      'randompick'     => 'Randomly pick',
     'randomorder'    => 'Randomly ordered',      'randomorder'    => 'Randomly ordered',
               'gradable'       => 'Grade can be assigned to External Tool',
     'set'            => 'set to',      'set'            => 'set to',
     'del'            => 'deleted');      'del'            => 'deleted');
     my $filter = &Apache::loncommon::display_filter('docslog')."\n".      my $filter = &Apache::loncommon::display_filter('docslog')."\n".
Line 1111  sub docs_change_log { Line 1149  sub docs_change_log {
  $r->print('</ul>');   $r->print('</ul>');
  if ($docslog{$id}{'logentry'}{'parameter_res'}) {   if ($docslog{$id}{'logentry'}{'parameter_res'}) {
     $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');      $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
     foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {      foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
  if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {   if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 # FIXME: internationalization seems wrong here  # FIXME: internationalization seems wrong here
     $r->print('<li>'.      $r->print('<li>'.
Line 1863  sub do_paste_from_buffer { Line 1901  sub do_paste_from_buffer {
         }          }
         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {          if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
             my $prefix = $1;              my $prefix = $1;
             my $fromothercrs;               my $fromothercrs;
             #need to copy the db contents to a new one, unless this is a move.              #need to copy the db contents to a new one, unless this is a move.
             my %info = (              my %info = (
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           cnum => $coursenum,
                        );                         );
               if ($prefix eq 'ext.tool') {
                   if ($prefixchg{$suffix} eq 'docstosupp') { 
                       $info{'delgradable'} = 1;
                   }
               }
             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {              if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {                  unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                     $fromothercrs = 1;                      $fromothercrs = 1;
Line 1961  sub do_paste_from_buffer { Line 2004  sub do_paste_from_buffer {
                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},                      &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");                                            $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                 }                  }
               } elsif ($url =~ /ext\.tool$/) {
                   if (($newidx) && ($folder=~/^default/)) { 
                       my $marker = (split(m{/},$url))[4];
                       my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                       my $val = 'no';
                       if ($toolsettings{'gradable'}) {
                           $val = 'yes';
                       }
                       &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                                                     'string_yesno');
                       &remember_parms($newidx,'gradable','set',$val);
                   }
             }              }
             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).              $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                                               ':'.$ext.':normal:res';                                                ':'.$ext.':normal:res';
Line 2209  sub dbcopy { Line 2264  sub dbcopy {
                         }                          }
                     }                      }
                     $db_name =~ s{_\d*$ }{_$suffix}x;                      $db_name =~ s{_\d*$ }{_$suffix}x;
                       if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
                           delete($contents{'gradable'});
                       }
                     $result=&Apache::lonnet::put($db_name,\%contents,                      $result=&Apache::lonnet::put($db_name,\%contents,
                                                  $coursedom,$coursenum);                                                   $coursedom,$coursenum);
                     if ($result eq 'ok') {                      if ($result eq 'ok') {
Line 2493  sub url_paste_fixups { Line 2551  sub url_paste_fixups {
                         $changed = 1;                          $changed = 1;
                     }                      }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {              } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
                 next if ($skip);                  next if ($skip);
                 my $srcdom = $1;                  my $srcdom = $1;
                 my $srcnum = $2;                  my $srcnum = $2;
                   my $rem = $3;
                   my ($is_exttool,$exttoolchg);
                   if ($rem =~ m{\d+/ext\.tool$}) {
                       $is_exttool = 1;     
                   }
                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {                  if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
                     $rewrites->{$oldurl}{$id} = $ressrc;                      $rewrites->{$oldurl}{$id} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;                      $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;                      $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;                      $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                     $changed = 1;                      $changed = 1;
                       if ($is_exttool) {
                           $exttoolchg = 1;
                       }
                   } elsif (($rem =~ m{\d+/ext\.tool$}) &&
                            ($env{'form.docs.markedcopy_options'} ne 'move')) {
                       $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                       $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                       $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                       $changed = 1;
                       $exttoolchg = 1;
                   }
                   if (($is_exttool) && ($prefixchg)) {
                       if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                           if ($exttoolchg) {
                               $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                           }
                       }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {              } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||                  if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
Line 2766  sub apply_fixups { Line 2846  sub apply_fixups {
                     }                      }
                 }                  }
             }              }
             for (my $i=0; $i<@LONCAPA::map::order; $i++) {              my $total = scalar(@LONCAPA::map::order) - 1;
               for (my $i=$total; $i>=0; $i--) {
                 my $idx = $LONCAPA::map::order[$i];                  my $idx = $LONCAPA::map::order[$i];
                 if (defined($LONCAPA::map::resources[$idx])) {                  if (defined($LONCAPA::map::resources[$idx])) {
                     my $changed;                      my $changed;
Line 2776  sub apply_fixups { Line 2857  sub apply_fixups {
                         splice(@LONCAPA::map::order,$i,1);                          splice(@LONCAPA::map::order,$i,1);
                         if (ref($currparam{$idx}) eq 'ARRAY') {                          if (ref($currparam{$idx}) eq 'ARRAY') {
                             foreach my $name (@{$currparam{$idx}}) {                              foreach my $name (@{$currparam{$idx}}) {
                                 &LONCAPA::map::delparameter($idx,'parameter_'.$name);                                  &LONCAPA::map::delparameter($idx,$name);
                             }                              }
                         }                          }
                         next;                          next;
Line 2818  sub apply_fixups { Line 2899  sub apply_fixups {
             foreach my $idx (keys(%remparam)) {              foreach my $idx (keys(%remparam)) {
                 if (ref($remparam{$idx}) eq 'ARRAY') {                  if (ref($remparam{$idx}) eq 'ARRAY') {
                     foreach my $name (@{$remparam{$idx}}) {                         foreach my $name (@{$remparam{$idx}}) {   
                         &LONCAPA::map::delparameter($idx,'parameter_'.$name);                          &LONCAPA::map::delparameter($idx,$name);
                     }                      }
                 }                  }
             }              }
Line 4322  $form_end; Line 4403  $form_end;
         $reinit = &mt('(re-initialize course to access)');          $reinit = &mt('(re-initialize course to access)');
     }      }
     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;      $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
     if ($url =~ /$LONCAPA::assess_re/) {      if ($orig_url =~ /$LONCAPA::assess_re/) {
         $line.= '<br />';          $line.= '<br />';
         if ($curralias ne '') {          if ($curralias ne '') {
             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.              $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
Line 4732  sub list_symbs { Line 4813  sub list_symbs {
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   sub short_urls {
       my ($r,$canedit) = @_;
       my $crstype = &Apache::loncommon::course_type();
       my $formname = 'shortenurl';
       $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
       $r->print(&startContentScreen('tools'));
       my ($navmap,$errormsg) =
           &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my (%maps,%resources,%titles);
       if (!ref($navmap)) {
           $r->print($errormsg.
                     &endContentScreen());
           return '';
       } else {
           $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n".
           $r->rflush();
           my $readonly;
           if ($canedit) {
               my ($numnew,$errors) = &Apache::loncommon::make_short_symbs($cdom,$cnum,$navmap);
               if ($numnew) {
                   $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
               }
               if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   foreach my $error (@{$errors}) {
                       $r->print('<li>'.$error.'</li>');
                   }
                   $r->print('</ul><br />');
               }
           } else {
               $readonly = 1;
           }
           my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
           $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                                                                undef,undef,undef,undef,undef,\%currtiny,$readonly));
       }
       $r->print(&endContentScreen());
   }
   
 sub contentverifyform {  sub contentverifyform {
     my ($r) = @_;      my ($r) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
Line 5267  sub handler { Line 5390  sub handler {
   } elsif ($allowed && $env{'form.listsymbs'}) {    } elsif ($allowed && $env{'form.listsymbs'}) {
       &init_breadcrumbs('listsymbs','List Content IDs');        &init_breadcrumbs('listsymbs','List Content IDs');
       &list_symbs($r);        &list_symbs($r);
     } elsif ($allowed && $env{'form.shorturls'}) {
         &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
         &short_urls($r,$canedit);
   } elsif ($allowed && $env{'form.docslog'}) {    } elsif ($allowed && $env{'form.docslog'}) {
       &init_breadcrumbs('docslog','Show Log');        &init_breadcrumbs('docslog','Show Log');
       my $folder = $env{'form.folder'};        my $folder = $env{'form.folder'};
Line 5601  sub handler { Line 5727  sub handler {
                 }                  }
             }              }
             my $tabidstr = join("','",@tabids);              my $tabidstr = join("','",@tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);              %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
             my $posslti = keys(%ltitools);              my $posslti = keys(%ltitools);
             my $hostname = $r->hostname();              my $hostname = $r->hostname();
     $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,      $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
Line 6856  sub generate_admin_menu { Line 6982  sub generate_admin_menu {
                                          'vc'   => 'Verify Content',                                           'vc'   => 'Verify Content',
                                          'cv'   => 'Check/Set Resource Versions',                                           'cv'   => 'Check/Set Resource Versions',
                                          'ls'   => 'List Resource Identifiers',                                           'ls'   => 'List Resource Identifiers',
                                            'ct'   => 'Display/Set Shortened URLs for Deep-linking',
                                          'imse' => 'Export contents to IMS Archive',                                           'imse' => 'Export contents to IMS Archive',
                                          'dcd'  => "Copy $crstype Content to Authoring Space",                                           'dcd'  => "Copy $crstype Content to Authoring Space",
             );              );
Line 6906  sub generate_admin_menu { Line 7033  sub generate_admin_menu {
                     icon       => 'symbs.png',                      icon       => 'symbs.png',
                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"                      linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                 },                  },
                   {   linktext   => $lt{'ct'},
                       url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                       permission => 'F',
                       help       => 'Docs_Short_URLs',
                       icon       => 'shorturls.png',
                       linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   },
                 ]                  ]
         });          });
     if ($canedit) {      if ($canedit) {

Removed from v.1.643  
changed lines
  Added in v.1.651


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