diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -80,6 +80,7 @@ when "ruby" then Rouge::Lexers::Ruby.new when "python" then Rouge::Lexers::Python.new when "java" then Rouge::Lexers::Java.new + when "php" then Rouge::Lexers::PHP.new end @formatted_code = formatter.format(lexer.lex(@submission.source)) @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight') diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -89,8 +89,30 @@ render :action => 'edit' and return end end + if params[:file] and params[:file].content_type != 'application/pdf' + flash[:notice] = 'Error: Uploaded file is not PDF' + render :action => 'edit' and return + end if @problem.update_attributes(params[:problem]) flash[:notice] = 'Problem was successfully updated.' + unless params[:file] == nil or params[:file] == '' + flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' + out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" + if not FileTest.exists? out_dirname + Dir.mkdir out_dirname + end + + out_filename = "#{out_dirname}/#{@problem.name}.pdf" + if FileTest.exists? out_filename + File.delete out_filename + end + + File.open(out_filename,"wb") do |file| + file.write(params[:file].read) + end + @problem.description_filename = "#{@problem.name}.pdf" + @problem.save + end redirect_to :action => 'show', :id => @problem else render :action => 'edit' diff --git a/app/views/main/_submission.html.haml b/app/views/main/_submission.html.haml --- a/app/views/main/_submission.html.haml +++ b/app/views/main/_submission.html.haml @@ -2,6 +2,8 @@ %tr{:class => ((submission_counter%2==0) ? "info-even" : "info-odd")} %td.info{:align => "center"} = submission_counter+1 + %td.info{:align => "center"} + = link_to "##{submission.id}", controller: :graders, action: :submission, id: submission.id %td.info= format_short_time(submission.submitted_at) %td.info{:align => "center"} = link_to('[load]',{:action => 'source', :id => submission.id}) diff --git a/app/views/main/submission.html.haml b/app/views/main/submission.html.haml --- a/app/views/main/submission.html.haml +++ b/app/views/main/submission.html.haml @@ -13,6 +13,7 @@ - if @submissions.length>0 %table.info %tr.info-head + %th.info No. %th.info # %th.info At %th.info Source diff --git a/app/views/problems/_form.html.erb b/app/views/problems/_form.html.erb --- a/app/views/problems/_form.html.erb +++ b/app/views/problems/_form.html.erb @@ -48,5 +48,7 @@
<%= text_field 'problem', 'url' %>
Task PDF <%= file_field_tag 'file' %>
+ diff --git a/app/views/problems/edit.html.erb b/app/views/problems/edit.html.erb --- a/app/views/problems/edit.html.erb +++ b/app/views/problems/edit.html.erb @@ -1,6 +1,6 @@