Diff for /loncom/interface/loncourserespicker.pm between versions 1.12 and 1.15

version 1.12, 2015/04/09 17:57:05 version 1.15, 2018/01/12 13:33:38
Line 39  resources are to be either: Line 39  resources are to be either:
 (a) exported to an IMS Content Package  (a) exported to an IMS Content Package
 (b) subject to access blocking for the duriation of an exam/quiz.  (b) subject to access blocking for the duriation of an exam/quiz.
 (c) dumped to an Authoring Space  (c) dumped to an Authoring Space
   (d) receive shortened URLs to be used when deep-linking into a course
   
 =head1 DESCRIPTION  =head1 DESCRIPTION
   
Line 75  select items.  Checking a folder causes Line 76  select items.  Checking a folder causes
 within the folder. Unchecking a resource causing unchecking of folders  within the folder. Unchecking a resource causing unchecking of folders
 containing the item back up to the top level.  containing the item back up to the top level.
   
 Inputs: 9.  Inputs: 11.
    - $navmap  -- Reference to LON-CAPA navmap object      - $navmap  -- Reference to LON-CAPA navmap object 
                 (encapsulates information about resources in the course).                   (encapsulates information about resources in the course). 
   
    - $context -- Context in which course resource selection is being made.     - $context -- Context in which course resource selection is being made.
                  Currently imsexport and examblock are supported.                   Currently imsexport, examblock, dumpdocs, and shorturls
                    are supported.
   
    - $formname  -- Name of the form in the window from which the pop-up     - $formname  -- Name of the form in the window from which the pop-up
                    used to select course items was launched.                      used to select course items was launched. 
Line 107  Inputs: 9. Line 109  Inputs: 9.
    - $uploadedfiles -- Reference to hash: keys are paths to files in     - $uploadedfiles -- Reference to hash: keys are paths to files in
                        /home/httpd/lonUsers/$cdom/$1/$2/$3/$cnum/userfiles.                         /home/httpd/lonUsers/$cdom/$1/$2/$3/$cnum/userfiles.
   
      - $tiny -- Reference to hash: keys are symbs of course items for which
                 shortened URLs have already been created.
   
      - $readonly -- if true, no "check all" or "uncheck all" buttons will
                     be displayed, and checkboxes will be disabled, if this 
                     is for an exam block or for shortened URL creation.
   
   
 Output: $output is the HTML mark-up for display/selection of content  Output: $output is the HTML mark-up for display/selection of content
         items in the pop-up window.          items in the pop-up window.
Line 206  use Apache::lonlocal; Line 215  use Apache::lonlocal;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 sub create_picker {  sub create_picker {
     my ($navmap,$context,$formname,$crstype,$blockedmaps,$blockedresources,$block,$preamble,$numhome,$uploadedfiles) = @_;      my ($navmap,$context,$formname,$crstype,$blockedmaps,$blockedresources,$block,$preamble,
           $numhome,$uploadedfiles,$tiny,$readonly) = @_;
     return unless (ref($navmap));      return unless (ref($navmap));
     my ($it,$output,$numdisc,%maps,%resources,%discussiontime,%currmaps,%currresources,%files);      my ($it,$output,$numdisc,%maps,%resources,%discussiontime,%currmaps,%currresources,%files,
           %shorturls,$chkname);
       $chkname = 'archive';
       if ($context eq 'shorturls') {
           $chkname = 'addtiny';
       }
     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);      $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
     if (ref($blockedmaps) eq 'HASH') {      if (ref($blockedmaps) eq 'HASH') {
         %currmaps = %{$blockedmaps};          %currmaps = %{$blockedmaps};
Line 217  sub create_picker { Line 232  sub create_picker {
         %currresources = %{$blockedresources};          %currresources = %{$blockedresources};
     } elsif (ref($uploadedfiles) eq 'HASH') {      } elsif (ref($uploadedfiles) eq 'HASH') {
         %files = %{$uploadedfiles};          %files = %{$uploadedfiles};
       } elsif (ref($tiny) eq 'HASH') {
           %shorturls = %{$tiny}; 
     }      }
     my @checked_maps;      my @checked_maps;
     my $curRes;      my $curRes;
Line 236  sub create_picker { Line 253  sub create_picker {
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};      my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     my $crsprefix = &propath($cdom,$cnum).'/userfiles/';      my $crsprefix = &propath($cdom,$cnum).'/userfiles/';
   
     my ($info,$display,$onsubmit,$togglebuttons);      my ($info,$display,$onsubmit,$togglebuttons,$disabled);
     if ($context eq 'examblock') {      if ($context eq 'examblock') {
         my $maps_elem = 'docs_maps_'.$block;          my $maps_elem = 'docs_maps_'.$block;
         my $res_elem = 'docs_resources_'.$block;          my $res_elem = 'docs_resources_'.$block;
         $onsubmit = ' onsubmit="return writeToOpener('."'$maps_elem','$res_elem'".');"';          $onsubmit = ' onsubmit="return writeToOpener('."'$maps_elem','$res_elem'".');"';
         $info = &mt('Items in '.lc($crstype).' for which access will be blocked.');          $info = &mt('Items in '.lc($crstype).' for which access will be blocked.');
           if ($readonly) {
               $disabled = ' disabled="disabled"';
           }
     }      }
     if ($context eq 'dumpdocs') {      if ($context eq 'dumpdocs') {
         $info = '<span class="LC_fontsize_medium">'.          $info = '<span class="LC_fontsize_medium">'.
                 &mt('Choose the uploaded course items and templated pages/problems to be copied to Authoring Space.').                  &mt('Choose the uploaded course items and templated pages/problems to be copied to Authoring Space.').
                 '</span><br /><br />';                  '</span><br /><br />';
         $startcount = 3 + $numhome;          $startcount = 3 + $numhome;
         $onsubmit = ' onsubmit="return checkUnique(document.'.$formname.',document.'.$formname.'.archive);"';          $onsubmit = ' onsubmit="return checkUnique(document.'.$formname.',document.'.$formname.'.'.$chkname.');"';
       } elsif ($context eq 'shorturls') {
           $info = '<span class="LC_fontsize_medium">'.
                   &mt('Choose the resource(s) and/or folder(s) from Main Content for which shortened URL(s) are needed.').
                   '</span><br /><br />';
     } elsif ($context eq 'imsexport') {      } elsif ($context eq 'imsexport') {
         $info = &mt('Choose which items you wish to export from your '.$crstype.'.');          $info = &mt('Choose which items you wish to export from your '.$crstype.'.');
         $startcount = 5;          $startcount = 5;
     }      }
     $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.      if ($disabled) {
                      'onclick="javascript:checkAll(document.'.$formname.'.archive)" />'.          $togglebuttons = '<br />';
                      '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.      } else {
                      ' onclick="javascript:uncheckAll(document.'.$formname.'.archive)" />';          $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
                            'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
                            '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.
                            ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
       }
     $display = '<form name="'.$formname.'" action="" method="post"'.$onsubmit.'>'."\n";      $display = '<form name="'.$formname.'" action="" method="post"'.$onsubmit.'>'."\n";
     if ($context eq 'imsexport') {      if ($context eq 'imsexport') {
         $display .= $info.          $display .= $info.
Line 278  sub create_picker { Line 306  sub create_picker {
                 '</fieldset>';                  '</fieldset>';
         }          }
         $display .= '</div>';          $display .= '</div>';
     } elsif ($context eq 'examblock') {      } elsif (($context eq 'examblock') || ($context eq 'shorturls')) {
         $display .= $info.$togglebuttons;          $display .= $info.$togglebuttons;
     } elsif ($context eq 'dumpdocs') {      } elsif ($context eq 'dumpdocs') {
         $display .= $preamble.          $display .= $preamble.
Line 299  sub create_picker { Line 327  sub create_picker {
         $display .= '<th>'.&mt('Access blocked?').'</th>';          $display .= '<th>'.&mt('Access blocked?').'</th>';
     } elsif ($context eq 'dumpdocs') {      } elsif ($context eq 'dumpdocs') {
         $display .= '<th>'.&mt('Copy?').'</th>'.          $display .= '<th>'.&mt('Copy?').'</th>'.
                     '<th>'.&mt("Title in $crstype").                      '<th>'.&mt("Title in $crstype").'</th>'.
                     '<th>'.&mt('Internal Identifier').'</th>'.                      '<th>'.&mt('Internal Identifier').'</th>'.
                     '<th>'.&mt('Save as ...').'</th>';                      '<th>'.&mt('Save as ...').'</th>';
       } elsif ($context eq 'shorturls') {
           $display .= '<th colspan="2">'.&mt('Tiny URL').'</th>'.
                       '<th>'.&mt("Title in $crstype").'</th>';
     }      }
     $display .= &Apache::loncommon::end_data_table_header_row();      $display .= &Apache::loncommon::end_data_table_header_row();
     while ($curRes = $it->next()) {      while ($curRes = $it->next()) {
Line 327  sub create_picker { Line 358  sub create_picker {
                 }                  }
             }              }
             $count ++;              $count ++;
             my $currelem;              my ($currelem,$mapurl,$is_map);
             if ($context eq 'imsexport') {              if ($context eq 'imsexport') {
                 $currelem = $count+$boards+$startcount;                  $currelem = $count+$boards+$startcount;
             } else {              } else {
                 $currelem = $count+$startcount;                  $currelem = $count+$startcount;
             }              }
             $display .= &Apache::loncommon::start_data_table_row().              $display .= &Apache::loncommon::start_data_table_row()."\n";
                        '<td>'."\n".  
                        '<input type="checkbox" name="archive" value="'.$count.'" ';  
             if (($curRes->is_sequence()) || ($curRes->is_page())) {              if (($curRes->is_sequence()) || ($curRes->is_page())) {
                 $lastcontainer = $currelem;                  $lastcontainer = $currelem;
                 $display .= 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" ';                  $mapurl = (&Apache::lonnet::decode_symb($symb))[2];
                 my $mapurl = (&Apache::lonnet::decode_symb($symb))[2];                  $is_map = 1;
                 if ($currmaps{$mapurl}) {              }
                     $display .= 'checked="checked"';              if ($context eq 'shorturls') {
                     push(@checked_maps,$currelem);                  if ($shorturls{$symb}) {
                       $display .= '<td>&nbsp;</td><td align="right"><b>'."/tiny/$cdom/$shorturls{$symb}".'</b></td>'."\n";
                   } else {
                       $display .= '<td align="left"><label><input type="checkbox" name="'.$chkname.'" '.
                                   'value="'.$count.'"'.$disabled.' />'.&mt('Add').'</label></td>'.
                                   '<td>&nbsp;</td>'."\n";
                 }                  }
             } else {              } else {
                 if ($curRes->is_problem()) {                  $display .= '<td><input type="checkbox" name="'.$chkname.'" value="'.$count.'" ';
                     $numprobs ++;                  if ($is_map) {
                 }                      $display .= 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" ';
                 $display .= 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" ';                      if ($currmaps{$mapurl}) {
                 if ($currresources{$symb}) {                          $display .= 'checked="checked"';
                     $display .= 'checked="checked"';                          push(@checked_maps,$currelem);
                       }
                   } else {
                       if ($curRes->is_problem()) {
                          $numprobs ++;
                       }
                       $display .= 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" ';
                       if ($currresources{$symb}) {
                           $display .= 'checked="checked"';
                       }
                 }                  }
                   $display .= $disabled.' />'."\n";
             }              }
             $display .= ' />'."\n";  
             if ($context eq 'dumpdocs') {              if ($context eq 'dumpdocs') {
                 $display .= '</td><td valign="top">';                  $display .= '</td><td valign="top">';
               } elsif ($context eq 'shorturls') {
                   $display .= '<td valign="top">';
             }              }
             for (my $i=0; $i<$depth; $i++) {              for (my $i=0; $i<$depth; $i++) {
                 $display .= "$whitespace\n";                  $display .= "$whitespace\n";
Line 450  sub create_picker { Line 495  sub create_picker {
            &mt('Export').'" /></p>';             &mt('Export').'" /></p>';
         $numcount = $count + $boards + $startcount;          $numcount = $count + $boards + $startcount;
     } elsif ($context eq 'examblock') {      } elsif ($context eq 'examblock') {
         $display .=          unless ($readonly) {
             '<p>'.              $display .=
             '<input type="submit" name="resourceblocks" value="'.                  '<p>'.
             &mt('Copy Choices to Main Window').'" /></p>';                  '<input type="submit" name="resourceblocks" value="'.
                   &mt('Copy Choices to Main Window').'" /></p>';
           }
         $numcount = $count + $startcount;          $numcount = $count + $startcount;
     } elsif ($context eq 'dumpdocs') {      } elsif ($context eq 'dumpdocs') {
         $display .= '</fieldset>'.          $display .= '</fieldset>'.
Line 462  sub create_picker { Line 509  sub create_picker {
                     '<input type="submit" name="dumpcourse" value="'.&mt("Copy $crstype Content").'" />'.                      '<input type="submit" name="dumpcourse" value="'.&mt("Copy $crstype Content").'" />'.
                     '</div>';                      '</div>';
         $numcount = $count + $startcount;          $numcount = $count + $startcount;
       } elsif ($context eq 'shorturls') {
           unless ($readonly) {
               $display .=
                   '<p>'.
                   '<input type="submit" name="shorturls" value="'.
                   &mt('Create Tiny URL(s)').'" /></p>';
           }
     }      }
     $display .= '</form>';      $display .= '</form>';
     my $scripttag =       my $scripttag = 
         &respicker_javascript($startcount,$numcount,$context,$formname,\%children,          &respicker_javascript($startcount,$numcount,$context,$formname,\%children,
                               \%hierarchy,\@checked_maps,$numhome);                                \%hierarchy,\@checked_maps,$numhome,$chkname);
     if ($context eq 'dumpdocs') {      if (($context eq 'dumpdocs') || ($context eq 'shorturls')) {
         return $scripttag.$display;           return $scripttag.$display; 
     }      }
     my ($title,$crumbs,$args);      my ($title,$crumbs,$args);
Line 484  sub create_picker { Line 538  sub create_picker {
         $output .= &Apache::lonhtmlcommon::breadcrumbs('IMS Export').          $output .= &Apache::lonhtmlcommon::breadcrumbs('IMS Export').
                    &Apache::londocs::startContentScreen('tools');                     &Apache::londocs::startContentScreen('tools');
     } elsif ($context eq 'dumpdocs') {      } elsif ($context eq 'dumpdocs') {
          $output .= &Apache::lonhtmlcommon::breadcrumbs('Copying to Authoring Space').          $output .= &Apache::lonhtmlcommon::breadcrumbs('Copying to Authoring Space').
                     &Apache::londocs::startContentScreen('tools');                     &Apache::londocs::startContentScreen('tools');
     }      }
     $output .= $display;      $output .= $display;
     if ($context eq 'examblock') {      if ($context eq 'examblock') {
Line 498  sub create_picker { Line 552  sub create_picker {
   
 sub respicker_javascript {  sub respicker_javascript {
     my ($startcount,$numitems,$context,$formname,$children,$hierarchy,      my ($startcount,$numitems,$context,$formname,$children,$hierarchy,
         $checked_maps,$numhome) = @_;          $checked_maps,$numhome,$chkname) = @_;
     return unless ((ref($children) eq 'HASH') && (ref($hierarchy) eq 'HASH')      my $check_uncheck = <<"FIRST";
                    && (ref($checked_maps) eq 'ARRAY'));  
     my ($elem,$nested,$nameforelem);  
     if ($context eq 'dumpdocs') {  
         $elem='((parseInt(item)-'.$startcount.')*2)+'.$startcount;  
         $nested='((parseInt(nesting[item][i])-'.$startcount.')*2)+'.$startcount;  
         $nameforelem=$elem+1;  
     } else {  
         $elem='parseInt(item)';  
         $nested='parseInt(nesting[item][i])';  
     }  
     my $scripttag = <<"START";  
 <script type="text/javascript">  
 // <![CDATA[  
 function checkAll(field) {  function checkAll(field) {
     if (field.length > 0) {      if (field.length > 0) {
         for (i = 0; i < field.length; i++) {          for (i = 0; i < field.length; i++) {
Line 532  function uncheckAll(field) { Line 573  function uncheckAll(field) {
         field.checked = false;          field.checked = false;
     }      }
 }  }
   FIRST
       if ($context eq 'shorturls') {
           return <<"END";
   <script type="text/javascript">
   // <![CDATA[
   $check_uncheck
   // ]]>
   </script>
   END
       }
       return unless ((ref($children) eq 'HASH') && (ref($hierarchy) eq 'HASH')
                      && (ref($checked_maps) eq 'ARRAY'));
       my ($elem,$nested,$nameforelem);
       if ($context eq 'dumpdocs') {
           $elem='((parseInt(item)-'.$startcount.')*2)+'.$startcount;
           $nested='((parseInt(nesting[item][i])-'.$startcount.')*2)+'.$startcount;
           $nameforelem=$elem+1;
       } else {
           $elem='parseInt(item)';
           $nested='parseInt(nesting[item][i])';
       }
       my $scripttag = <<"START";
   <script type="text/javascript">
   // <![CDATA[
   $check_uncheck
   
 function checkFolder(form,item) {  function checkFolder(form,item) {
     var elem = $elem;      var elem = $elem;
Line 592  EXTRA Line 658  EXTRA
         my $blankmsg = &mt('An item selected has no filename set in the "Save as ..." column.');          my $blankmsg = &mt('An item selected has no filename set in the "Save as ..." column.');
         my $dupmsg = &mt('Items selected for copying need unique filenames in the "Save as ..." column.');          my $dupmsg = &mt('Items selected for copying need unique filenames in the "Save as ..." column.');
         my $homemsg = &mt('An Authoring Space needs to be selected.');          my $homemsg = &mt('An Authoring Space needs to be selected.');
           &js_escape(\$blankmsg);
           &js_escape(\$dupmsg);
           &js_escape(\$homemsg);
         $scripttag .= <<"EXTRA";          $scripttag .= <<"EXTRA";
   
 function checkUnique(form,field) {  function checkUnique(form,field) {
Line 682  END Line 751  END
 function writeToOpener(maps,resources) {  function writeToOpener(maps,resources) {
     var checkedmaps = '';      var checkedmaps = '';
     var checkedresources = '';      var checkedresources = '';
     for (var i=0; i<document.$formname.archive.length; i++) {      for (var i=0; i<document.$formname.${chkname}.length; i++) {
         if (document.$formname.archive[i].checked) {          if (document.$formname.${chkname}[i].checked) {
             var isResource = 1;              var isResource = 1;
             var include = 1;              var include = 1;
             var elemnum = i+1+$startcount;              var elemnum = i+1+$startcount;
Line 704  function writeToOpener(maps,resources) { Line 773  function writeToOpener(maps,resources) {
             }              }
             if (include == 1) {              if (include == 1) {
                 if (isResource == 1) {                  if (isResource == 1) {
                     checkedresources += document.$formname.archive[i].value+',';                      checkedresources += document.$formname.${chkname}[i].value+',';
                 } else {                  } else {
                     checkedmaps += document.$formname.archive[i].value+',';                      checkedmaps += document.$formname.${chkname}[i].value+',';
                 }                  }
             }              }
         }          }
Line 740  sub get_navmap_object { Line 809  sub get_navmap_object {
                                                        undef,{'only_body' => 1,}).                                                         undef,{'only_body' => 1,}).
                       '<h2>'.&mt('Resource Display Failed').'</h2>';                          '<h2>'.&mt('Resource Display Failed').'</h2>';  
         } elsif ($context eq 'dumpdocs') {          } elsif ($context eq 'dumpdocs') {
             $outcome = '<h2>'.&mt('Copying to Authoring Space unavailable');              $outcome = '<h2>'.&mt('Copying to Authoring Space unavailable').'</h2>';
           } elsif ($context eq 'shorturls') {
               $outcome = '<h2>'.&mt('Display/Setting of shortened URLs unavailable').'</h2>';
         }          }
         $outcome .= '<div class="LC_error">';          $outcome .= '<div class="LC_error">';
         if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
Line 749  sub get_navmap_object { Line 820  sub get_navmap_object {
             $outcome .= &mt('Unable to retrieve information about course contents');              $outcome .= &mt('Unable to retrieve information about course contents');
         }          }
         $outcome .= '</div>';          $outcome .= '</div>';
         if (($context eq 'imsexport') || ($context eq 'dumpdocs')) {          if (($context eq 'imsexport') || ($context eq 'dumpdocs') || ($context eq 'shorturls') ) {
             $outcome .= '<a href="/adm/coursedocs">';              $outcome .= '<a href="/adm/coursedocs">';
             if ($crstype eq 'Community') {              if ($crstype eq 'Community') {
                 $outcome .= &mt('Return to Community Editor');                  $outcome .= &mt('Return to Community Editor');
Line 799  sub enumerate_course_contents { Line 870  sub enumerate_course_contents {
                     }                      }
                 }                  }
                 $count ++;                  $count ++;
                 if (($curRes->is_sequence()) || ($curRes->is_page())) {                  if ($context eq 'shorturls') {
                     $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];  
                 } else {  
                     $resource_symb->{$count} = $ressymb;                      $resource_symb->{$count} = $ressymb;
                   } else {
                       if (($curRes->is_sequence()) || ($curRes->is_page())) {
                           $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];
                       } else {
                           $resource_symb->{$count} = $ressymb;
                       }
                 }                  }
                 $titleref->{$count} = $curRes->title();                  $titleref->{$count} = $curRes->title();
             }              }

Removed from v.1.12  
changed lines
  Added in v.1.15


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