--- loncom/homework/lonhomework.pm 2014/08/07 19:53:19 1.345 +++ loncom/homework/lonhomework.pm 2015/04/16 10:13:29 1.351 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.345 2014/08/07 19:53:19 musolffc Exp $ +# $Id: lonhomework.pm,v 1.351 2015/04/16 10:13:29 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -469,7 +469,6 @@ sub check_access { if ( $tries eq '' ) { $tries = '0'; } if ( $maxtries eq '' && $env{'request.state'} ne 'construct') { $maxtries = '2'; } - $Apache::lonhomework::results{'resource.'.$id.'.maxtries'}=$maxtries; if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } # if (correct and show prob status) or excused then CANNOT_ANSWER if ( ($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/) @@ -590,7 +589,7 @@ sub showarray { sub showhashsubset { my ($hash,$keyre) = @_; my $resultkey; - foreach $resultkey (sort keys %$hash) { + foreach $resultkey (sort(keys(%$hash))) { if ($resultkey !~ /$keyre/) { next; } if (ref($$hash{$resultkey}) eq 'ARRAY' ) { &Apache::lonxml::debug("$resultkey ---- ". @@ -768,8 +767,7 @@ sub analyze_header { .&Apache::loncommon::head_subbox( &Apache::loncommon::CSTR_pageheader()); $result .= - &Apache::lonxml::message_location().' -
'. ''. @@ -783,8 +781,9 @@ sub analyze_header {
- -
'; + ' + .&Apache::lonxml::message_location(). + ''; &Apache::lonxml::add_messages(\$result); $request->print($result); $request->rflush(); @@ -963,9 +962,8 @@ sub editxmlmode { $problem=''; } - if (($env{'form.problemmode'} eq 'saveeditxml') || - ($env{'form.problemmode'} eq 'saveviewxml') || + ($env{'form.problemmode'} eq 'saveviewxml') || ($env{'form.problemmode'} eq 'undoxml')) { my $error=&handle_save_or_undo($request,\$problem, \$env{'form.editxmltext'}); @@ -1011,27 +1009,80 @@ sub editxmlmode { '
'. &Apache::structuretags::remember_problem_state().' -
- -
-

'.&mt('Problem Editing').' '.&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').'

-
- '.&Apache::loncommon::helpLatexCheatsheet('Problem_LON-CAPA_Functions','Script Functions').' -
'; +
+
'. + &mt('Problem Editing').' '.&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index'). + '
'; - $result.=''. + $result.=''. &Apache::structuretags::problem_edit_buttons('editxml'); + $result.='
'; + + unless ($env{'environment.nocodemirror'}) { + # dropdown menues + $result .= '
    '. + &Apache::lonmenu::create_submenu("#", "", &mt("Templates"), + &Apache::structuretags::insert_menu_datastructure(), + "").'
'; + } + $result .= '
    '; + + $result .= Apache::lonmenu::create_submenu("#", "", + &mt("Help") . ' ' . &mt(', + &Apache::structuretags::helpmenu_datastructure(),""); + + $result.="
"; - $result.='
'.&Apache::lonxml::message_location().'
'. - '
- '.&Apache::loncommon::end_page(); - &Apache::lonxml::add_messages(\$result); - $request->print($result); + '; + my $resource = $env{'request.ambiguous'}; + unless($env{'environment.nocodemirror'}){ + + $result .= ' + + '; + } + $result .= &Apache::loncommon::end_page(); + &Apache::lonxml::add_messages(\$result); + $request->print($result); } return ''; } @@ -1066,8 +1117,10 @@ sub renderpage { $problem=''; my $filename=(split('/',$file))[-1]; my $error = - &mt('Unable to find [_1]', - ''.$filename.''); + '

' + .&mt('Unable to find [_1]', + ''.$filename.'') + ."

"; $result.= &Apache::loncommon::simple_error_page($request,'Not available', $error,{'no_auto_mt_msg' => 1}); @@ -1118,7 +1171,25 @@ sub finished_parsing { undef($Apache::lonhomework::parsing_a_task); } -sub get_template_list { +# function extracted from get_template_html +# returns "key" -> list +# key: path of template +# value 1: title +# value 2: category +# value 3: name of help topic ??? +sub get_template_list{ + my ($extension) = @_; + + my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. + '/templates/*.'.$extension); + @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), + (&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')), + &mt(&Apache::lonnet::metadata($_, 'help'))]} (@files); + @files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files); + return @files; +} + +sub get_template_html { my ($extension) = @_; my $result; my @allnames; @@ -1127,12 +1198,7 @@ sub get_template_list { if ($extension eq 'survey' || $extension eq 'exam') { $glob_extension = 'problem'; } - my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. - '/templates/*.'.$glob_extension); - @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), - (&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')), - &Apache::lonnet::metadata($_, 'help')]} (@files); - @files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files); + my @files = &get_template_list($extension); my ($midpoint,$seconddiv,$numfiles); my @noexamplelink = ('blank.problem','blank.library','script.library'); $numfiles = 0; @@ -1194,6 +1260,12 @@ sub get_template_list { sub newproblem { my ($request) = @_; + if ($env{'form.mode'} eq 'blank'){ + my $dest = &Apache::lonnet::filelocation("",$request->uri); + &File::Copy::copy('/home/httpd/html/res/adm/includes/templates/blank.problem',$dest); + &renderpage($request,$dest); + return; + } if ($env{'form.template'}) { my $file = $env{'form.template'}; my $dest = &Apache::lonnet::filelocation("",$request->uri); @@ -1204,7 +1276,7 @@ sub newproblem { my ($extension) = ($request->uri =~ m/\.(\w+)$/); &Apache::lonxml::debug("Looking for :$extension:"); - my $templatelist=&get_template_list($extension); + my $templatelist=&get_template_html($extension); if ($env{'form.newfile'} && !$templatelist) { # no templates found my $templatefilename = @@ -1278,7 +1350,7 @@ sub handler { my $file=&Apache::lonnet::filelocation("",$request->uri); #check if we know where we are - if ($env{'request.course.fn'} && !&Apache::lonnet::symbread()) { + if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) { # if we are browsing we might not be able to know where we are if ($Apache::lonhomework::browse ne 'F' && $env{'request.state'} ne "construct") { @@ -1316,6 +1388,8 @@ sub handler { &renderpage($request,$file); } } else { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['mode']); # requested file doesn't exist in contruction space &newproblem($request); }