[LON-CAPA-cvs] cvs: modules /gerd/gcistuff londocs.pm
www
www@source.lon-capa.org
Thu, 16 Jul 2009 19:06:59 -0000
This is a MIME encoded message
--www1247771219
Content-Type: text/plain
www Thu Jul 16 19:06:59 2009 EDT
Modified files:
/modules/gerd/gcistuff londocs.pm
Log:
Translate problem selection into map
--www1247771219
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20090716190659.txt"
Index: modules/gerd/gcistuff/londocs.pm
diff -u modules/gerd/gcistuff/londocs.pm:1.6 modules/gerd/gcistuff/londocs.pm:1.7
--- modules/gerd/gcistuff/londocs.pm:1.6 Thu Jul 16 08:49:08 2009
+++ modules/gerd/gcistuff/londocs.pm Thu Jul 16 19:06:59 2009
@@ -2,7 +2,7 @@
# Documents
# Modified for GCI Concept Inventory Assemby
#
-# $Id: londocs.pm,v 1.6 2009/07/16 08:49:08 www Exp $
+# $Id: londocs.pm,v 1.7 2009/07/16 19:06:59 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,9 +56,6 @@
my $hashtied;
my %alreadyseen=();
-my $hadchanges;
-
-
my %help=();
@@ -188,1025 +185,37 @@
}
sub mapread {
- my ($coursenum,$coursedom,$map)=@_;
+ my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
return
- &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map);
+ &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence');
}
sub storemap {
- my ($coursenum,$coursedom,$map)=@_;
+ my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
my ($outtext,$errtext)=
- &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
+ &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence',1);
if ($errtext) { return ($errtext,2); }
-
- $hadchanges=1;
return ($errtext,0);
}
-
-sub group_import {
- my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
-
- while (@files) {
- my ($name, $url, $residx) = @{ shift(@files) };
- if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
- && ($caller eq 'londocs')
- && (!&Apache::lonnet::stat_file($url))) {
-
- my $errtext = '';
- my $fatal = 0;
- my $newmapstr = '<map>'."\n".
- '<resource id="1" src="" type="start"></resource>'."\n".
- '<link from="1" to="2" index="1"></link>'."\n".
- '<resource id="2" src="" type="finish"></resource>'."\n".
- '</map>';
- $env{'form.output'}=$newmapstr;
- my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
- 'output',$1.$2);
- if ($result != m|^/uploaded/|) {
- $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
- $fatal = 2;
- }
- if ($fatal) {
- return ($errtext,$fatal);
- }
- }
- if ($url) {
- if (!$residx
- || defined($LONCAPA::map::zombies[$residx])) {
- $residx = &LONCAPA::map::getresidx($url,$residx);
- push(@LONCAPA::map::order, $residx);
- }
- my $ext = 'false';
- if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
- $url = &LONCAPA::map::qtunescape($url);
- $name = &LONCAPA::map::qtunescape($name);
- $LONCAPA::map::resources[$residx] =
- join(':', ($name, $url, $ext, 'normal', 'res'));
- }
- }
- return &storemap($coursenum, $coursedom, $folder.'.'.$container);
-}
-
-sub breadcrumbs {
- my ($where,$allowed,$type)=@_;
- &Apache::lonhtmlcommon::clear_breadcrumbs();
- my (@folders);
- if ($env{'form.pagepath'}) {
- @folders = split('&',$env{'form.pagepath'});
- } else {
- @folders=split('&',$env{'form.folderpath'});
- }
- my $folderpath;
- my $cpinfo='';
- my $plain='';
- my $randompick=-1;
- my $isencrypted=0;
- my $ishidden=0;
- my $is_random_order=0;
- while (@folders) {
- my $folder=shift(@folders);
- my $foldername=shift(@folders);
- if ($folderpath) {$folderpath.='&';}
- $folderpath.=$folder.'&'.$foldername;
- my $url='/adm/coursedocs?folderpath='.
- &escape($folderpath);
- my $name=&unescape($foldername);
-# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
- $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
- if ($1 ne '') {
- $randompick=$1;
- } else {
- $randompick=-1;
- }
- if ($2) { $ishidden=1; }
- if ($3) { $isencrypted=1; }
- if ($4 ne '') { $is_random_order = 1; }
- if ($folder eq 'supplemental') {
- if ($allowed) {
- $name = &mt('Supplemental '.$type.' Documents');
- } else {
- $name = &mt($type.' Documents');
- }
- }
- &Apache::lonhtmlcommon::add_breadcrumb(
- {'href'=>$url.$cpinfo,
- 'title'=>$name,
- 'text'=>$name,
- 'no_mt'=>1,
- });
- $plain.=$name.' > ';
- }
- $plain=~s/\>\;\s*$//;
- return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
- 'LC_docs_path', undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
-}
-
-sub log_docs {
- return &Apache::lonnet::instructor_log('docslog',@_);
-}
-
-{
- my @oldresources=();
- my @oldorder=();
- my $parmidx;
- my %parmaction=();
- my %parmvalue=();
- my $changedflag;
-
- sub snapshotbefore {
- @oldresources=@LONCAPA::map::resources;
- @oldorder=@LONCAPA::map::order;
- $parmidx=undef;
- %parmaction=();
- %parmvalue=();
- $changedflag=0;
- }
-
- sub remember_parms {
- my ($idx,$parameter,$action,$value)=@_;
- $parmidx=$idx;
- $parmaction{$parameter}=$action;
- $parmvalue{$parameter}=$value;
- $changedflag=1;
- }
-
- sub log_differences {
- my ($plain)=@_;
- my %storehash=('folder' => $plain,
- 'currentfolder' => $env{'form.folder'});
- if ($parmidx) {
- $storehash{'parameter_res'}=$oldresources[$parmidx];
- foreach my $parm (keys(%parmaction)) {
- $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
- $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
- }
- }
- my $maxidx=$#oldresources;
- if ($#LONCAPA::map::resources>$#oldresources) {
- $maxidx=$#LONCAPA::map::resources;
- }
- for (my $idx=0; $idx<=$maxidx; $idx++) {
- if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
- $storehash{'before_resources_'.$idx}=$oldresources[$idx];
- $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
- $changedflag=1;
- }
- if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
- $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
- $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
- $changedflag=1;
- }
- }
- $storehash{'maxidx'}=$maxidx;
- if ($changedflag) { &log_docs(\%storehash); }
- }
-}
-
-
-
-
-
-sub docs_change_log {
- my ($r)=@_;
- my $folder=$env{'form.folder'};
- $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
- my %docslog=&Apache::lonnet::dump('nohist_docslog',
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
-
- if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
-
- $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
- '<input type="hidden" name="docslog" value="1" />');
-
- my %saveable_parameters = ('show' => 'scalar',);
- &Apache::loncommon::store_course_settings('docs_log',
- \%saveable_parameters);
- &Apache::loncommon::restore_course_settings('docs_log',
- \%saveable_parameters);
- if (!$env{'form.show'}) { $env{'form.show'}=10; }
- my %lt=('hiddenresource' => 'Resources hidden',
- 'encrypturl' => 'URL hidden',
- 'randompick' => 'Randomly pick',
- 'randomorder' => 'Randomly ordered',
- 'set' => 'set to',
- 'del' => 'deleted');
- $r->print(&Apache::loncommon::display_filter().
- '<input type="hidden" name="folder" value="'.$folder.'" />'.
- '<input type="submit" value="'.&mt('Display').'" /></form>');
- $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
- '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
- &mt('After').'</th>'.
- &Apache::loncommon::end_data_table_header_row());
- my $shown=0;
- foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
- if ($env{'form.displayfilter'} eq 'currentfolder') {
- if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
- }
- my @changes=keys(%{$docslog{$id}{'logentry'}});
- if ($env{'form.displayfilter'} eq 'containing') {
- my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
- &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
- foreach my $key (@changes) {
- $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
- }
- if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
- }
- my $count = 0;
- my $time =
- &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
- my $plainname =
- &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
- $docslog{$id}{'exe_udom'});
- my $about_me_link =
- &Apache::loncommon::aboutmewrapper($plainname,
- $docslog{$id}{'exe_uname'},
- $docslog{$id}{'exe_udom'});
- my $send_msg_link='';
- if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
- || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
- $send_msg_link ='<br />'.
- &Apache::loncommon::messagewrapper(&mt('Send message'),
- $docslog{$id}{'exe_uname'},
- $docslog{$id}{'exe_udom'});
- }
- $r->print(&Apache::loncommon::start_data_table_row());
- $r->print('<td>'.$time.'</td>
- <td>'.$about_me_link.
- '<br /><tt>'.$docslog{$id}{'exe_uname'}.
- ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
- $send_msg_link.'</td><td>'.
- $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
-# Before
- for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
- my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
- my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
- if ($oldname ne $newname) {
- $r->print(&LONCAPA::map::qtescape($oldname));
- }
- }
- $r->print('<ul>');
- for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
- if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
- $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
- }
- }
- $r->print('</ul>');
-# After
- $r->print('</td><td>');
-
- for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
- my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
- my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
- if ($oldname ne '' && $oldname ne $newname) {
- $r->print(&LONCAPA::map::qtescape($newname));
- }
- }
- $r->print('<ul>');
- for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
- if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
- $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
- }
- }
- $r->print('</ul>');
- if ($docslog{$id}{'logentry'}{'parameter_res'}) {
- $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
- foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
- if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
- $r->print('<li>'.
- &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
- $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
- .'</li>');
- }
- }
- $r->print('</ul>');
- }
-# End
- $r->print('</td>'.&Apache::loncommon::end_data_table_row());
- $shown++;
- if (!($env{'form.show'} eq &mt('all')
- || $shown<=$env{'form.show'})) { last; }
- }
- $r->print(&Apache::loncommon::end_data_table());
-}
-
-sub update_paste_buffer {
- my ($coursenum,$coursedom) = @_;
-
- return if (!defined($env{'form.markcopy'}));
- return if (!defined($env{'form.copyfolder'}));
- return if ($env{'form.markcopy'} < 0);
-
- my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
- $env{'form.copyfolder'});
-
- return if ($fatal);
-
-# Mark for copying
- my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
- if (&is_supplemental_title($title)) {
- &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
- ($title) = &parse_supplemental_title($title);
- } elsif ($env{'docs.markedcopy_supplemental'}) {
- &Apache::lonnet::delenv('docs.markedcopy_supplemental');
- }
- $url=~s{http(:|:)//https(:|:)//}{https$2//};
-
- &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
- 'docs.markedcopy_url' => $url});
- delete($env{'form.markcopy'});
-}
-
-sub print_paste_buffer {
- my ($r,$container) = @_;
- return if (!defined($env{'docs.markedcopy_url'}));
-
- $r->print(<<ENDPASTE);
-<form name="pasteform" action="/adm/coursedocs" method="post"><p>
-ENDPASTE
- $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
-
- my $type;
- if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
- $type = &mt('External Resource');
- $r->print($type.': '.
- &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
- &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
- } else {
- my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
- my $icon = &Apache::loncommon::icon($extension);
- if ($extension eq 'sequence' &&
- $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
- $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
- $icon .= '/folder_closed.gif';
- }
- $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
- $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
- }
- if ($container eq 'page') {
- $r->print('
- <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
- <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
-');
- } else {
- $r->print('
- <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
-');
- }
- $r->print('</p></form>');
-}
-
-sub do_paste_from_buffer {
- my ($coursenum,$coursedom,$folder) = @_;
-
- if (!$env{'form.pastemarked'}) {
- return;
- }
-
-# paste resource to end of list
- my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
- my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
-# Maps need to be copied first
- if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
- $title=&mt('Copy of').' '.$title;
- my $newid=$$.int(rand(100)).time;
- my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
- if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
- my $path = $1;
- my $prefix = $2;
- my $ancestor = $3;
- if (length($ancestor) > 10) {
- $ancestor = substr($ancestor,-10,10);
- }
- $oldid = $path.$prefix.$ancestor;
- }
- my $counter = 0;
- my $newurl=$oldid.$newid.'.'.$ext;
- my $is_unique = &uniqueness_check($newurl);
- while (!$is_unique && $counter < 100) {
- $counter ++;
- $newid ++;
- $newurl = $oldid.$newid;
- $is_unique = &uniqueness_check($newurl);
- }
- if (!$is_unique) {
- if ($url=~/\.page$/) {
- return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
- } else {
- return &mt('Paste failed: an error occurred creating a unique URL for the folder');
- }
- }
- my $storefn=$newurl;
- $storefn=~s{^/\w+/$match_domain/$match_username/}{};
- my $paste_map_result =
- &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
- &Apache::lonnet::getfile($url));
- if ($paste_map_result eq '/adm/notfound.html') {
- if ($url=~/\.page$/) {
- return &mt('Paste failed: an error occurred saving the composite page');
- } else {
- return &mt('Paste failed: an error occurred saving the folder');
- }
- }
- $url = $newurl;
- }
-# published maps can only exists once, so remove it from paste buffer when done
- if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
- &Apache::lonnet::delenv('docs.markedcopy');
- }
- if ($url=~ m{/smppg$}) {
- my $db_name = &Apache::lonsimplepage::get_db_name($url);
- if ($db_name =~ /^smppage_/) {
- #simple pages, need to copy the db contents to a new one.
- my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
- my $now = time();
- $db_name =~ s{_\d*$ }{_$now}x;
- my $result=&Apache::lonnet::put($db_name,\%contents,
- $coursedom,$coursenum);
- $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
- $title=&mt('Copy of').' '.$title;
- }
- }
- $title = &LONCAPA::map::qtunescape($title);
- my $ext='false';
- if ($url=~m{^http(|s)://}) { $ext='true'; }
- $url = &LONCAPA::map::qtunescape($url);
-# Now insert the URL at the bottom
- my $newidx = &LONCAPA::map::getresidx($url);
- if ($env{'docs.markedcopy_supplemental'}) {
- if ($folder =~ /^supplemental/) {
- $title = $env{'docs.markedcopy_supplemental'};
- } else {
- (undef,undef,$title) =
- &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
- }
- } else {
- if ($folder=~/^supplemental/) {
- $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
- $env{'user.domain'}.'___&&&___'.$title;
- }
- }
-
- $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
- push(@LONCAPA::map::order, $newidx);
- return 'ok';
-# Store the result
-}
-
-sub uniqueness_check {
- my ($newurl) = @_;
- my $unique = 1;
- foreach my $res (@LONCAPA::map::order) {
- my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
- $url=&LONCAPA::map::qtescape($url);
- if ($newurl eq $url) {
- $unique = 0;
- last;
- }
- }
- return $unique;
-}
-
-my %parameter_type = ( 'randompick' => 'int_pos',
- 'hiddenresource' => 'string_yesno',
- 'encrypturl' => 'string_yesno',
- 'randomorder' => 'string_yesno',);
-my $valid_parameters_re = join('|',keys(%parameter_type));
-# set parameters
-sub update_parameter {
-
- return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
-
- my $which = $env{'form.changeparms'};
- my $idx = $env{'form.setparms'};
- if ($env{'form.'.$which.'_'.$idx}) {
- my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
- : 'yes';
- &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
- $parameter_type{$which});
- &remember_parms($idx,$which,'set',$value);
- } else {
- &LONCAPA::map::delparameter($idx,'parameter_'.$which);
-
- &remember_parms($idx,$which,'del');
- }
- return 1;
-}
-
-
-sub handle_edit_cmd {
- my ($coursenum,$coursedom) =@_;
-
- my ($cmd,$idx)=split('_',$env{'form.cmd'});
-
- my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
- my ($title, $url, @rrest) = split(':', $ratstr);
-
- if ($cmd eq 'del') {
- if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
- ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
- &Apache::lonnet::removeuploadedurl($url);
- } else {
- &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
- }
- splice(@LONCAPA::map::order, $idx, 1);
-
- } elsif ($cmd eq 'cut') {
- &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
- splice(@LONCAPA::map::order, $idx, 1);
-
- } elsif ($cmd eq 'up'
- && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
- @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
-
- } elsif ($cmd eq 'down'
- && defined($LONCAPA::map::order[$idx+1])) {
- @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
-
- } elsif ($cmd eq 'rename') {
-
- my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
- if ($comment=~/\S/) {
- $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
- $comment.':'.join(':', $url, @rrest);
- }
-# Devalidate title cache
- my $renamed_url=&LONCAPA::map::qtescape($url);
- &Apache::lonnet::devalidate_title_cache($renamed_url);
- } else {
- return 0;
- }
- return 1;
-}
-
-sub editor {
- my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
-
- my $container= ($env{'form.pagepath'}) ? 'page'
- : 'sequence';
-
- my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
- $folder.'.'.$container);
- return $errtext if ($fatal);
-
- if ($#LONCAPA::map::order<1) {
- my $idx=&LONCAPA::map::getresidx();
- if ($idx<=0) { $idx=1; }
- $LONCAPA::map::order[0]=$idx;
- $LONCAPA::map::resources[$idx]='';
- }
-
- my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
- &breadcrumbs($folder,$allowed,$type);
- $r->print($breadcrumbtrail);
-
-# ------------------------------------------------------------ Process commands
-
-# ---------------- if they are for this folder and user allowed to make changes
- if (($allowed) && ($env{'form.folder'} eq $folder)) {
-# set parameters and change order
- &snapshotbefore();
-
- if (&update_parameter()) {
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- return $errtext if ($fatal);
- }
-
- if ($env{'form.newpos'} && $env{'form.currentpos'}) {
-# change order
- my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
- splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
-
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- return $errtext if ($fatal);
- }
-
- if ($env{'form.pastemarked'}) {
- my $paste_res =
- &do_paste_from_buffer($coursenum,$coursedom,$folder);
- if ($paste_res eq 'ok') {
- ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
- return $errtext if ($fatal);
- } elsif ($paste_res ne '') {
- $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
- }
- }
-
- $r->print($upload_output);
-
- if (&handle_edit_cmd()) {
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- return $errtext if ($fatal);
- }
-# Group import/search
- if ($env{'form.importdetail'}) {
- my @imports;
- foreach my $item (split(/\&/,$env{'form.importdetail'})) {
- if (defined($item)) {
- my ($name,$url,$residx)=
- map {&unescape($_)} split(/\=/,$item);
- push(@imports, [$name, $url, $residx]);
- }
- }
- ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
- $container,'londocs',@imports);
- return $errtext if ($fatal);
- }
-# Loading a complete map
- if ($env{'form.loadmap'}) {
- if ($env{'form.importmap'}=~/\w/) {
- foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
- my ($title,$url,$ext,$type)=split(/\:/,$res);
- my $idx=&LONCAPA::map::getresidx($url);
- $LONCAPA::map::resources[$idx]=$res;
- $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
- }
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
- return $errtext if ($fatal);
- } else {
- $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
-
- }
- }
- &log_differences($plain);
- }
-# ---------------------------------------------------------------- End commands
-# ---------------------------------------------------------------- Print screen
- my $idx=0;
- my $shown=0;
- if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
- $r->print('<p>'.&mt('Parameters').':<ul>'.
- ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
- ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
- ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
- '</ul></p>');
- }
- if ($randompick>=0) {
- $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
- }
- if ($is_random_order) {
- $r->print('<p>'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'</p>');
- }
- $r->print('<table class="LC_docs_editor">');
- foreach my $res (@LONCAPA::map::order) {
- my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
- $name=&LONCAPA::map::qtescape($name);
- $url=&LONCAPA::map::qtescape($url);
- unless ($name) { $name=(split(/\//,$url))[-1]; }
- unless ($name) { $idx++; next; }
- $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
- $coursenum));
- $idx++;
- $shown++;
- }
- unless ($shown) {
- $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
- }
- $r->print("\n</table>\n");
- if ($allowed) {
- &print_paste_buffer($r,$container);
- }
- return;
-}
-
-# --------------------------------------------------------------- An entry line
-
-sub entryline {
- my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
-
- my ($foldertitle,$pagetitle,$renametitle);
- if (&is_supplemental_title($title)) {
- ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
- $pagetitle = $foldertitle;
- } else {
- $title=&HTML::Entities::encode($title,'"<>&\'');
- $renametitle=$title;
- $foldertitle=$title;
- $pagetitle=$title;
- }
-
- my $orderidx=$LONCAPA::map::order[$index];
-
-
- $renametitle=~s/\\/\\\\/g;
- $renametitle=~s/\"\;/\\\"/g;
- $renametitle=~s/ /%20/g;
- my $line='<tr>';
- my ($form_start,$form_end);
-# Edit commands
- my ($container, $type, $esc_path, $path, $symb);
- if ($env{'form.folderpath'}) {
- $type = 'folder';
- $container = 'sequence';
- $esc_path=&escape($env{'form.folderpath'});
- $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
- # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
- }
- if ($env{'form.pagepath'}) {
- $type = $container = 'page';
- $esc_path=&escape($path = $env{'form.pagepath'});
- $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
- $symb=&escape($env{'form.pagesymb'});
- }
- my $cpinfo='';
- if ($allowed) {
- my $incindex=$index+1;
- my $selectbox='';
- if (($folder!~/^supplemental/) &&
- ($#LONCAPA::map::order>0) &&
- ((split(/\:/,
- $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
- ne '') &&
- ((split(/\:/,
- $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
- ne '')) {
- $selectbox=
- '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
- '<select name="newpos" onchange="this.form.submit()">';
- for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
- if ($i==$incindex) {
- $selectbox.='<option value="" selected="selected">('.$i.')</option>';
- } else {
- $selectbox.='<option value="'.$i.'">'.$i.'</option>';
- }
- }
- $selectbox.='</select>';
- }
- my %lt=&Apache::lonlocal::texthash(
- 'up' => 'Move Up',
- 'dw' => 'Move Down',
- 'rm' => 'Remove',
- 'ct' => 'Cut',
- 'rn' => 'Rename',
- 'cp' => 'Copy');
- my $nocopy=0;
- my $nocut=0;
- if ($url=~/\.(page|sequence)$/) {
- if ($url =~ m{/res/}) {
- # no copy for published maps
- $nocopy = 1;
- } else {
- foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
- my ($title,$url,$ext,$type)=split(/\:/,$item);
- if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
- $nocopy=1;
- last;
- }
- }
- }
- }
- if ($url=~/^\/res\/lib\/templates\//) {
- $nocopy=1;
- $nocut=1;
- }
- my $copylink=' ';
- my $cutlink=' ';
-
- my $skip_confirm = 0;
- if ( $folder =~ /^supplemental/
- || ($url =~ m{( /smppg$
- |/syllabus$
- |/aboutme$
- |/navmaps$
- |/bulletinboard$
- |\.html$
- |^/adm/wrapper/ext)}x)) {
- $skip_confirm = 1;
- }
-
- if (!$nocopy) {
- $copylink=(<<ENDCOPY);
-<a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
-ENDCOPY
- }
- if (!$nocut) {
- $cutlink=(<<ENDCUT);
-<a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
-ENDCUT
- }
- $form_start = (<<END);
- <form action="/adm/coursedocs" method="post">
- <input type="hidden" name="${type}path" value="$path" />
- <input type="hidden" name="${type}symb" value="$symb" />
- <input type="hidden" name="setparms" value="$orderidx" />
- <input type="hidden" name="changeparms" value="0" />
-END
- $form_end = '</form>';
- $line.=(<<END);
-<td>
- <table class="LC_docs_entry_move">
- <tr>
- <td>
- <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" /></a>
- </td>
- </tr>
- <tr>
- <td>
- <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" /></a>
- </td>
- </tr>
- </table>
-</td>
-<td>
- $form_start
- $selectbox
- $form_end
-</td>
-<td class="LC_docs_entry_commands">
- <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
-$cutlink
- <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
-$copylink
-</td>
-END
-
- }
-# Figure out what kind of a resource this is
- my ($extension)=($url=~/\.(\w+)$/);
- my $uploaded=($url=~/^\/*uploaded\//);
- my $icon=&Apache::loncommon::icon($url);
- my $isfolder=0;
- my $ispage=0;
- my $folderarg;
- my $pagearg;
- my $pagefile;
- if ($uploaded) {
- if ($extension eq 'sequence') {
- $icon=$iconpath.'/folder_closed.gif';
- $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
- $url='/adm/coursedocs?';
- $folderarg=$1;
- $isfolder=1;
- } elsif ($extension eq 'page') {
- $icon=$iconpath.'/page.gif';
- $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
- $pagearg=$1;
- $url='/adm/coursedocs?';
- $ispage=1;
- } else {
- &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
- }
- }
-
- my $orig_url = $url;
- $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
- my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
- if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
- my $symb=&Apache::lonnet::symbclean(
- &Apache::lonnet::declutter('uploaded/'.
- $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
- $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
- '.sequence').
- '___'.$residx.'___'.
- &Apache::lonnet::declutter($url));
- (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
- $url=&Apache::lonnet::clutter($url);
- if ($url=~/^\/*uploaded\//) {
- $url=~/\.(\w+)$/;
- my $embstyle=&Apache::loncommon::fileembstyle($1);
- if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
- $url='/adm/wrapper'.$url;
- } elsif ($embstyle eq 'ssi') {
- #do nothing with these
- } elsif ($url!~/\.(sequence|page)$/) {
- $url='/adm/coursedocs/showdoc'.$url;
- }
- } elsif ($url=~m|^/ext/|) {
- $url='/adm/wrapper'.$url;
- $external = 1;
- }
- if (&Apache::lonnet::symbverify($symb,$url)) {
- $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
- } else {
- $url='';
- }
- if ($container eq 'page') {
- my $symb=$env{'form.pagesymb'};
-
- $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
- $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
- }
- }
- my ($parameterset,$rand_order_text) = (' ', ' ');
- if ($isfolder || $extension eq 'sequence') {
- my $foldername=&escape($foldertitle);
- my $folderpath=$env{'form.folderpath'};
- if ($folderpath) { $folderpath.='&' };
-# Append randompick number, hidden, and encrypted with ":" to foldername,
-# so it gets transferred between levels
- $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
- 'parameter_randompick'))[0]
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_hiddenresource'))[0]=~/^yes$/i)
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_encrypturl'))[0]=~/^yes$/i)
- .':'.((&LONCAPA::map::getparameter($orderidx,
- 'parameter_randomorder'))[0]=~/^yes$/i);
- $url.='folderpath='.&escape($folderpath).$cpinfo;
- $parameterset='<label>'.&mt('Randomly Pick: ').
- '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
- (&LONCAPA::map::getparameter($orderidx,
- 'parameter_randompick'))[0].
- '" />'.
-'<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
- my $ro_set=
- ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
- $rand_order_text ='
-<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
- }
- if ($ispage) {
- my $pagename=&escape($pagetitle);
- my $pagepath;
- my $folderpath=$env{'form.folderpath'};
- if ($folderpath) { $pagepath = $folderpath.'&' };
- $pagepath.=$pagearg.'&'.$pagename;
- my $symb=$env{'form.pagesymb'};
- if (!$symb) {
- my $path='uploaded/'.
- $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
- $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
- $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
- $residx,
- $path.$pagearg.'.page');
- }
- $url.='pagepath='.&escape($pagepath).
- '&pagesymb='.&escape($symb).$cpinfo;
- }
- if ($external) {
- my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
- $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
- } else {
- undef($external);
- }
- $line.='
- <td class="LC_docs_entry_icon">
- '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
- </td>
- <td class="LC_docs_entry_title">
- '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
- </td>";
- if (($allowed) && ($folder!~/^supplemental/)) {
- my %lt=&Apache::lonlocal::texthash(
- 'hd' => 'Hidden',
- 'ec' => 'URL hidden');
- my $enctext=
- ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
- my $hidtext=
- ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
- $line.=(<<ENDPARMS);
- <td class="LC_docs_entry_parameter">
- $form_start
- <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
- $form_end
- </td>
- <td class="LC_docs_entry_parameter">
- $form_start
- <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
- $form_end
- </td>
- <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
- <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
-ENDPARMS
- }
- $line.="</tr>";
- return $line;
-}
-
-sub changewarning {
- my ($r,$postexec,$message,$url)=@_;
- if (!&is_hash_old()) { return; }
- my $pathvar='folderpath';
- my $path=&escape($env{'form.folderpath'});
- if (!defined($url)) {
- if (defined($env{'form.pagepath'})) {
- $pathvar='pagepath';
- $path=&escape($env{'form.pagepath'});
- $path.='&pagesymb='.&escape($env{'form.pagesymb'});
- }
- $url='/adm/coursedocs?'.$pathvar.'='.$path;
- }
- my $course_type = &Apache::loncommon::course_type();
- if (!defined($message)) {
- $message='Changes will become active for your current session after [_1], or the next time you log in.';
+sub chosen_to_map {
+ my %chosenproblems=();
+ foreach my $item (@chosen) {
+ $chosenproblems{$item}=1;
+ }
+ @LONCAPA::map::order=();
+ @LONCAPA::map::resources=();
+ for (my $idx=0;$idx<=$#allprobs;$idx++) {
+ my $residx=$idx+1;
+ if ($chosenproblems{$allprobs[$idx]}) {
+ push(@LONCAPA::map::order,$residx);
+ my $url = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
+ my $name = &LONCAPA::map::qtunescape('Problem '.$allprobs[$idx]);
+ $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
+ }
}
- $r->print("\n\n".
-'<script type="text/javascript">'."\n".
-'// <![CDATA['."\n".
-'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
-'// ]]>'."\n".
-'</script>'."\n".
-'<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
-'<input type="hidden" name="orgurl" value="'.$url.
-'" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
-&mt($message,' <input type="hidden" name="'.
- $env{'request.role'}.'" value="1" /><input type="button" value="'.
- &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
-$help{'Caching'}.'</p></form>'."\n\n");
}
# empty cleanup handler
@@ -1237,9 +246,14 @@
@chosen=@defchosen;
# see if there is user input that needs to be stored
&evaluate();
+ &chosen_to_map();
+ &storemap();
# bring up the selection screen
&listresources($r);
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
+1;
+__END__
+
--www1247771219--