--- loncom/interface/loncourserespicker.pm 2015/04/09 17:57:05 1.12 +++ loncom/interface/loncourserespicker.pm 2024/04/16 15:35:23 1.16 @@ -1,6 +1,6 @@ # The LearningOnline Network # -# $Id: loncourserespicker.pm,v 1.12 2015/04/09 17:57:05 raeburn Exp $ +# $Id: loncourserespicker.pm,v 1.16 2024/04/16 15:35:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,6 +39,7 @@ resources are to be either: (a) exported to an IMS Content Package (b) subject to access blocking for the duriation of an exam/quiz. (c) dumped to an Authoring Space +(d) receive shortened URLs to be used when deep-linking into a course =head1 DESCRIPTION @@ -75,12 +76,13 @@ select items. Checking a folder causes within the folder. Unchecking a resource causing unchecking of folders containing the item back up to the top level. -Inputs: 9. +Inputs: 11. - $navmap -- Reference to LON-CAPA navmap object (encapsulates information about resources in the course). - $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 used to select course items was launched. @@ -107,6 +109,13 @@ Inputs: 9. - $uploadedfiles -- Reference to hash: keys are paths to files in /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 items in the pop-up window. @@ -206,9 +215,15 @@ use Apache::lonlocal; use LONCAPA qw(:DEFAULT :match); 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)); - my ($it,$output,$numdisc,%maps,%resources,%discussiontime,%currmaps,%currresources,%files); + my ($it,$output,$numdisc,%discussiontime,%currmaps,%currresources,%files, + %shorturls,$chkname); + $chkname = 'archive'; + if ($context eq 'shorturls') { + $chkname = 'addtiny'; + } $it = $navmap->getIterator(undef,undef,undef,1,undef,undef); if (ref($blockedmaps) eq 'HASH') { %currmaps = %{$blockedmaps}; @@ -217,6 +232,8 @@ sub create_picker { %currresources = %{$blockedresources}; } elsif (ref($uploadedfiles) eq 'HASH') { %files = %{$uploadedfiles}; + } elsif (ref($tiny) eq 'HASH') { + %shorturls = %{$tiny}; } my @checked_maps; my $curRes; @@ -236,27 +253,38 @@ sub create_picker { my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $crsprefix = &propath($cdom,$cnum).'/userfiles/'; - my ($info,$display,$onsubmit,$togglebuttons); + my ($info,$display,$onsubmit,$togglebuttons,$disabled); if ($context eq 'examblock') { my $maps_elem = 'docs_maps_'.$block; my $res_elem = 'docs_resources_'.$block; $onsubmit = ' onsubmit="return writeToOpener('."'$maps_elem','$res_elem'".');"'; $info = &mt('Items in '.lc($crstype).' for which access will be blocked.'); + if ($readonly) { + $disabled = ' disabled="disabled"'; + } } if ($context eq 'dumpdocs') { $info = ''. &mt('Choose the uploaded course items and templated pages/problems to be copied to Authoring Space.'). '

'; $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 = ''. + &mt('Choose the resource(s) and/or folder(s) from Main Content for which shortened URL(s) are needed.'). + '

'; } elsif ($context eq 'imsexport') { $info = &mt('Choose which items you wish to export from your '.$crstype.'.'); $startcount = 5; } - $togglebuttons = ''. - '  '; + if ($disabled) { + $togglebuttons = '
'; + } else { + $togglebuttons = ''. + '  '; + } $display = '
'."\n"; if ($context eq 'imsexport') { $display .= $info. @@ -278,7 +306,7 @@ sub create_picker { ''; } $display .= ''; - } elsif ($context eq 'examblock') { + } elsif (($context eq 'examblock') || ($context eq 'shorturls')) { $display .= $info.$togglebuttons; } elsif ($context eq 'dumpdocs') { $display .= $preamble. @@ -299,9 +327,12 @@ sub create_picker { $display .= ''.&mt('Access blocked?').''; } elsif ($context eq 'dumpdocs') { $display .= ''.&mt('Copy?').''. - ''.&mt("Title in $crstype"). + ''.&mt("Title in $crstype").''. ''.&mt('Internal Identifier').''. ''.&mt('Save as ...').''; + } elsif ($context eq 'shorturls') { + $display .= ''.&mt('Tiny URL').''. + ''.&mt("Title in $crstype").''; } $display .= &Apache::loncommon::end_data_table_header_row(); while ($curRes = $it->next()) { @@ -327,35 +358,49 @@ sub create_picker { } } $count ++; - my $currelem; + my ($currelem,$mapurl,$is_map); if ($context eq 'imsexport') { $currelem = $count+$boards+$startcount; } else { $currelem = $count+$startcount; } - $display .= &Apache::loncommon::start_data_table_row(). - ''."\n". - 'is_sequence()) || ($curRes->is_page())) { $lastcontainer = $currelem; - $display .= 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '; - my $mapurl = (&Apache::lonnet::decode_symb($symb))[2]; - if ($currmaps{$mapurl}) { - $display .= 'checked="checked"'; - push(@checked_maps,$currelem); + $mapurl = (&Apache::lonnet::decode_symb($symb))[2]; + $is_map = 1; + } + if ($context eq 'shorturls') { + if ($shorturls{$symb}) { + $display .= ' '."/tiny/$cdom/$shorturls{$symb}".''."\n"; + } else { + $display .= ''. + ' '."\n"; } } else { - if ($curRes->is_problem()) { - $numprobs ++; - } - $display .= 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '; - if ($currresources{$symb}) { - $display .= 'checked="checked"'; + $display .= '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') { $display .= ''; + } elsif ($context eq 'shorturls') { + $display .= ''; } for (my $i=0; $i<$depth; $i++) { $display .= "$whitespace\n"; @@ -450,10 +495,12 @@ sub create_picker { &mt('Export').'" />

'; $numcount = $count + $boards + $startcount; } elsif ($context eq 'examblock') { - $display .= - '

'. - '

'; + unless ($readonly) { + $display .= + '

'. + '

'; + } $numcount = $count + $startcount; } elsif ($context eq 'dumpdocs') { $display .= ''. @@ -462,12 +509,19 @@ sub create_picker { ''. ''; $numcount = $count + $startcount; + } elsif ($context eq 'shorturls') { + unless ($readonly) { + $display .= + '

'. + '

'; + } } $display .= '
'; my $scripttag = &respicker_javascript($startcount,$numcount,$context,$formname,\%children, - \%hierarchy,\@checked_maps,$numhome); - if ($context eq 'dumpdocs') { + \%hierarchy,\@checked_maps,$numhome,$chkname); + if (($context eq 'dumpdocs') || ($context eq 'shorturls')) { return $scripttag.$display; } my ($title,$crumbs,$args); @@ -484,8 +538,8 @@ sub create_picker { $output .= &Apache::lonhtmlcommon::breadcrumbs('IMS Export'). &Apache::londocs::startContentScreen('tools'); } elsif ($context eq 'dumpdocs') { - $output .= &Apache::lonhtmlcommon::breadcrumbs('Copying to Authoring Space'). - &Apache::londocs::startContentScreen('tools'); + $output .= &Apache::lonhtmlcommon::breadcrumbs('Copying to Authoring Space'). + &Apache::londocs::startContentScreen('tools'); } $output .= $display; if ($context eq 'examblock') { @@ -498,21 +552,8 @@ sub create_picker { sub respicker_javascript { my ($startcount,$numitems,$context,$formname,$children,$hierarchy, - $checked_maps,$numhome) = @_; - 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"; - +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"; +